minimal adjustments
[dotfiles/.git] / .config / coc / extensions / node_modules / coc-prettier / node_modules / @eslint / eslintrc / node_modules / type-fest / source / set-optional.d.ts
1 /**
2 Create a type that makes the given keys optional. The remaining keys are kept as is. The sister of the `SetRequired` type.
3
4 Use-case: You want to define a single model where the only thing that changes is whether or not some of the keys are optional.
5
6 @example
7 ```
8 import {SetOptional} from 'type-fest';
9
10 type Foo = {
11         a: number;
12         b?: string;
13         c: boolean;
14 }
15
16 type SomeOptional = SetOptional<Foo, 'b' | 'c'>;
17 // type SomeOptional = {
18 //      a: number;
19 //      b?: string; // Was already optional and still is.
20 //      c?: boolean; // Is now optional.
21 // }
22 ```
23 */
24 export type SetOptional<BaseType, Keys extends keyof BaseType = keyof BaseType> =
25         // Pick just the keys that are not optional from the base type.
26         Pick<BaseType, Exclude<keyof BaseType, Keys>> &
27         // Pick the keys that should be optional from the base type and make them optional.
28         Partial<Pick<BaseType, Keys>> extends
29         // If `InferredType` extends the previous, then for each key, use the inferred type key.
30         infer InferredType
31                 ? {[KeyType in keyof InferredType]: InferredType[KeyType]}
32                 : never;