/** Tries to match the TS's builtin string `enum` type (e.g. `typeof Enum`) */ export type EnumString = { [key: string]: string }; export type KeysOfUnion = T extends T ? keyof T: never; /** * Accepts a value from `TEnum` as an enum key (e.g. `Enum.Foo`), * or as a string literal (e.g. 'Foo'). * * ### Example * ``` * enum E { Foo, Bar } * let x: EnumValuesLiteral; * * x = E.Foo; * x = E.Bar; * * x = 'Foo'; * x = 'Bar'; * ``` */ export type EnumValuesLiteral = TEnum | `${TEnum}`; /** * Accepts a specific key from `TEnum` either as a enum key (e.g. `Enum.Foo`), * or as a string literal (e.g. 'Foo'). * * A less brittle way of writing `Enum.Foo | 'Foo'` (i.e. because the keys will be in sync * when renaming an enum entry, or error when given an invalid key). * * ### Example * ``` * enum E { Foo, Bar } * let x: EnumValueLiteral; * * x = E.Foo; * x = 'Foo'; * * x = E.Bar // error * x = 'Bar' // error * * let z: EnumValueLiteral; // error * ``` */ export type EnumValueLiteral = TKey | TEnum[TKey]; export type KeyMapType = K; export type NeverUndefined = T extends undefined | null ? never : T; /** Can be either `null` or `undefined` (it doesn't really matter). */ export type Nullish = T | null | undefined;