1 | import type {Simplify} from './simplify';
|
2 |
|
3 |
|
4 | type RequiredFilter<Type, Key extends keyof Type> = undefined extends Type[Key]
|
5 | ? Type[Key] extends undefined
|
6 | ? Key
|
7 | : never
|
8 | : Key;
|
9 |
|
10 |
|
11 | type OptionalFilter<Type, Key extends keyof Type> = undefined extends Type[Key]
|
12 | ? Type[Key] extends undefined
|
13 | ? never
|
14 | : Key
|
15 | : never;
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 |
|
29 |
|
30 |
|
31 |
|
32 |
|
33 |
|
34 |
|
35 |
|
36 |
|
37 |
|
38 |
|
39 |
|
40 |
|
41 |
|
42 |
|
43 | export type EnforceOptional<ObjectType> = Simplify<{
|
44 | [Key in keyof ObjectType as RequiredFilter<ObjectType, Key>]: ObjectType[Key]
|
45 | } & {
|
46 | [Key in keyof ObjectType as OptionalFilter<ObjectType, Key>]?: Exclude<ObjectType[Key], undefined>
|
47 | }>;
|