/** * Get the keys of FirstType without any keys of SecondType. */ type Without = { [KeyType in Exclude]?: never; }; /** * Create a type that has mutually exclusive keys. * No unique keys of FirstType can be used simultaneously with any unique keys of SecondType. * * Example: * `const myVar: XOR` * * @see https://github.com/maninak/ts-xor/tree/master#description */ export type XOR = FirstType | SecondType extends object ? (Without & SecondType) | (Without & FirstType) : FirstType | SecondType; /** * Create a type where at least one of the properties of a type(can be any property) is required to exist. * Optionally the set of required properties may be restricted with the second generic type. * * @example * ``` * * type Responder = { * text?: () => string; * json?: () => string; * secure?: boolean; * }; * * const responder: RequireAtLeastOne = { * secure: true * }; * * const responder2: RequireAtLeastOne = { * json: () => '{"message": "ok"}' * }; * ``` * * @see https://stackoverflow.com/a/49725198 */ export type RequireAtLeastOne = Pick> & { [K in Keys]-?: Required> & Partial>>; }[Keys]; /** Similar to the builtin Extract, but checks the filter strictly */ export type StrictExtract> = Extract; /** * DeepRequired * * from https://github.com/piotrwitek/utility-types * * @desc Required that works for deeply nested structure * @example * // Expect: { * // first: { * // second: { * // name: string; * // }; * // }; * // } * type NestedProps = { * first?: { * second?: { * name?: string; * }; * }; * }; * type RequiredNestedProps = DeepRequired; */ export type DeepRequired = T extends (...args: any[]) => any ? T : T extends any[] ? _DeepRequiredArray : T extends object ? _DeepRequiredObject : T; export interface _DeepRequiredArray extends Array>> { } export type _DeepRequiredObject = { [P in keyof T]-?: DeepRequired>; }; export type NonUndefined = A extends undefined ? never : A; export declare const getTypedKeys: (input: Record) => T[]; export type OneOf = T extends [infer Only] ? Only : T extends [infer A, infer B, ...infer Rest] ? OneOf<[XOR, ...Rest]> : never; export type ValueOf = T[keyof T]; export type EnsureAllValues = { [K in T]: K; }; export type ExhaustiveList = (keyof EnsureAllValues)[]; export {};