/** * A type that represents either `A` or `B`. Shared properties retain their * types and unique properties are marked as optional. */ type Either = Partial & Partial & (A | B); /** * A type that represents a value that may be a promise or a regular value. */ type Awaitable = T | Promise; /** * A type that represents a type that is a prettified version of the original type. * The prettified type has all generics removed from intellisense and displays a flat object. */ type Prettify = { [K in keyof T]: T[K]; } & {}; /** * Mark properties of T as optional if Condition is true */ type ConditionalPartial = Condition extends true ? Partial : T; /** * Same as Nullable except without `null`. */ type Optional = T | undefined; /** * Types that can be used to index native JavaScript types, (Object, Array, etc.). */ type IndexSignature = string | number | symbol; /** * An object of any index-able type to avoid conflicts between `{}`, `Record`, `object`, etc. */ type Obj | object = Record | object> = { [K in keyof O as K extends never ? never : K]: K extends never ? never : O[K] extends never ? never : O[K]; } & Omit; /** * Any type that is indexable using `string`, `number`, or `symbol`. */ type Indexable = { [K: IndexSignature]: ValueTypes; } | Obj; /** * Picks only the optional properties from a type, removing the required ones. * Optionally, recurses through nested objects if `DEEP` is true. */ type PickOptional = { [K in keyof T as undefined extends T[K] ? K : never]: DEEP extends false ? T[K] : T[K] extends Optional ? PickOptional : T[K]; }; /** * Picks only the required fields out of a type, removing the optional ones. * Optionally, recurses through nested objects if `DEEP` is true. */ type PickRequired = { [K in keyof T as K extends keyof PickOptional ? never : K]: T[K] extends Indexable ? PickRequired : T[K]; }; /** * Picks only the required keys out of a type, removing the optional ones. * Optionally, recurses through nested objects if `DEEP` is true. */ type PickRequiredKeys = keyof PickRequired; /** * Picks only the optional keys out of a type, removing the required ones. * Optionally, recurses through nested objects if `DEEP` is true. */ type PickOptionalKeys = keyof PickOptional; /** * Recursively make all properties of type `T` optional. */ type DeepPartial = T extends object ? { [P in keyof T]?: DeepPartial; } : T; /** * Recursively make all properties of type `T` required. */ type DeepRequired = T extends object ? { [P in keyof T]-?: DeepRequired; } : T; export type { Awaitable as A, ConditionalPartial as C, DeepPartial as D, Either as E, Indexable as I, PickRequiredKeys as P, Prettify as a, DeepRequired as b, PickOptional as c, PickOptionalKeys as d, PickRequired as e };