1 | import type {IfUnknown} from './if-unknown';
|
2 | import type {BuiltIns, LiteralKeyOf} from './internal';
|
3 | import type {Merge} from './merge';
|
4 |
|
5 |
|
6 |
|
7 |
|
8 | export type PartialOnUndefinedDeepOptions = {
|
9 | |
10 |
|
11 |
|
12 |
|
13 |
|
14 | readonly recurseIntoArrays?: boolean;
|
15 | };
|
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 |
|
44 |
|
45 |
|
46 |
|
47 |
|
48 |
|
49 |
|
50 | export type PartialOnUndefinedDeep<T, Options extends PartialOnUndefinedDeepOptions = {}> = T extends Record<any, any> | undefined
|
51 | ? {[KeyType in keyof T as undefined extends T[KeyType] ? IfUnknown<T[KeyType], never, KeyType> : never]?: PartialOnUndefinedDeepValue<T[KeyType], Options>} extends infer U
|
52 | ? Merge<{[KeyType in keyof T as KeyType extends LiteralKeyOf<U> ? never : KeyType]: PartialOnUndefinedDeepValue<T[KeyType], Options>}, U>
|
53 | : never
|
54 | : T;
|
55 |
|
56 |
|
57 |
|
58 |
|
59 | type PartialOnUndefinedDeepValue<T, Options extends PartialOnUndefinedDeepOptions> = T extends BuiltIns | ((...arguments_: any[]) => unknown)
|
60 | ? T
|
61 | : T extends ReadonlyArray<infer U> // Test if type is array or tuple
|
62 | ? Options['recurseIntoArrays'] extends true // Check if option is activated
|
63 | ? U[] extends T // Check if array not tuple
|
64 | ? readonly U[] extends T
|
65 | ? ReadonlyArray<PartialOnUndefinedDeep<U, Options>> // Readonly array treatment
|
66 | : Array<PartialOnUndefinedDeep<U, Options>> // Mutable array treatment
|
67 | : PartialOnUndefinedDeep<{[Key in keyof T]: PartialOnUndefinedDeep<T[Key], Options>}, Options> // Tuple treatment
|
68 | : T
|
69 | : T extends Record<any, any> | undefined
|
70 | ? PartialOnUndefinedDeep<T, Options>
|
71 | : unknown;
|
72 |
|
\ | No newline at end of file |