/** * The type `{}` doesn't mean "any empty object", it means "any non-nullish value". * * Use the `AnyObject` type for objects whose structure is unknown. * * @see https://github.com/typescript-eslint/typescript-eslint/issues/2063#issuecomment-675156492 */ export type AnyObject = Record; /** * Takes a type and makes all properties partial within it. * * TODO: Implement the SDK & Patch logic -- this should stop being needed as things will be defined as Patches */ export type RecursivePartial = T extends object ? { [P in keyof T]?: RecursivePartial; } : T; /** * Partial only some properties. * * eg. PartialSome */ export type PartialSome = Pick, Keys> & Omit; /** * Unions all values of an object togethers -- antithesis to `keyof myObj`. */ export type ValueOf = T[keyof T]; /** * Never allow any properties of `Type`. * * Utility type, probably never a reason to export. */ type Never = { [K in keyof Type]?: never; }; /** * Either TypeA properties or TypeB properties -- never both. * * @example * ```ts * type MyType = EitherNotBoth<{ foo: boolean }, { bar: boolean }>; * * // Valid usages: * const objA: MyType = { * foo: true, * }; * const objB: MyType = { * bar: true, * }; * * // TS Error -- can't have both properties: * const objBoth: MyType = { * foo: true, * bar: true, * }; * * // TS Error -- must have at least one property: * const objNeither: MyType = { * }; * ``` */ export type EitherNotBoth = (TypeA & Never) | (TypeB & Never); /** * Either TypeA properties or TypeB properties or neither of the properties -- never both. * * @example * ```ts * type MyType = EitherOrBoth<{ foo: boolean }, { bar: boolean }>; * * // Valid usages: * const objA: MyType = { * foo: true, * }; * const objB: MyType = { * bar: true, * }; * const objBoth: MyType = { * foo: true, * bar: true, * }; * * // TS Error -- can't omit both properties: * const objNeither: MyType = { * }; * ``` */ export type EitherOrBoth = EitherNotBoth | (TypeA & TypeB); /** * Either TypeA properties or TypeB properties or neither of the properties -- never both. * * @example * ```ts * type MyType = EitherOrNone<{ foo: boolean }, { bar: boolean }>; * * // Valid usages: * const objA: MyType = { * foo: true, * }; * const objB: MyType = { * bar: true, * }; * const objNeither: MyType = { * }; * * // TS Error -- can't have both properties: * const objBoth: MyType = { * foo: true, * bar: true, * }; * ``` */ export type EitherOrNone = EitherNotBoth | (Never & Never); type Explode = keyof T extends infer K ? K extends unknown ? { [I in keyof T]: I extends K ? T[I] : never; } : never : never; type AtMostOne = Explode>; type AtLeastOne; }> = Partial & U[keyof U]; /** * Create a type where exactly one of multiple properties must be supplied. * * @example * ```ts * type Foo = ExactlyOne<{ a: number, b: string, c: boolean}>; * * // Valid usages: * const objA: Foo = { * a: 1, * }; * const objB: Foo = { * b: 'hi', * }; * const objC: Foo = { * c: true, * }; * * // TS Error -- can't have more than one property: * const objAll: Foo = { * a: 1, * b: 'hi', * c: true, * }; * ``` */ export type ExactlyOne = AtMostOne & AtLeastOne; export {}; //# sourceMappingURL=typeHelpers.d.ts.map