Sha256: f35a727758da36dd885a70dd13a74d9167691aaff662d50eaaf66ed591957702
Contents?: true
Size: 1.09 KB
Versions: 33
Compression:
Stored size: 1.09 KB
Contents
/** Create a type that requires all of the given keys or none of the given keys. The remaining keys are kept as is. Use-cases: - Creating interfaces for components with mutually-inclusive keys. The caveat with `RequireAllOrNone` is that TypeScript doesn't always know at compile time every key that will exist at runtime. Therefore `RequireAllOrNone` can't do anything to prevent extra keys it doesn't know about. @example ``` import type {RequireAllOrNone} from 'type-fest'; type Responder = { text?: () => string; json?: () => string; secure: boolean; }; const responder1: RequireAllOrNone<Responder, 'text' | 'json'> = { secure: true }; const responder2: RequireAllOrNone<Responder, 'text' | 'json'> = { text: () => '{"message": "hi"}', json: () => '{"message": "ok"}', secure: true }; ``` @category Object */ export type RequireAllOrNone<ObjectType, KeysType extends keyof ObjectType = never> = ( | Required<Pick<ObjectType, KeysType>> // Require all of the given keys. | Partial<Record<KeysType, never>> // Require none of the given keys. ) & Omit<ObjectType, KeysType>; // The rest of the keys.
Version data entries
33 entries across 33 versions & 1 rubygems