Closed samhh closed 2 years ago
functions/objects with omitted properties can
I had to test this so sharing my example for reference:
type English = (deps: { gender: string }) => string;
type Spanish = () => string;
type Translations = Spanish | English;
declare const t: Translations;
// No error ✅
t({ gender: "male" });
// Error ❌
t({});
^ And importantly it should error if you omit the argument.
Updated my example.
Some locales may legitimately not need a variable that others do, for example in the case of gender. When this happens, if there are no other interpolations, we're going to output incompatible types across locales:
Functions and strings can't unionise (no such value), however functions/objects with omitted properties can. Specifically: