1 | import type {BuiltIns} from './internal';
|
2 |
|
3 |
|
4 |
|
5 |
|
6 | export type PartialDeepOptions = {
|
7 | |
8 |
|
9 |
|
10 |
|
11 |
|
12 | readonly recurseIntoArrays?: boolean;
|
13 | };
|
14 |
|
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 |
|
51 |
|
52 |
|
53 |
|
54 |
|
55 |
|
56 |
|
57 |
|
58 |
|
59 |
|
60 |
|
61 |
|
62 | export type PartialDeep<T, Options extends PartialDeepOptions = {}> = T extends BuiltIns | (((...arguments_: any[]) => unknown)) | (new (...arguments_: any[]) => unknown)
|
63 | ? T
|
64 | : T extends Map<infer KeyType, infer ValueType>
|
65 | ? PartialMapDeep<KeyType, ValueType, Options>
|
66 | : T extends Set<infer ItemType>
|
67 | ? PartialSetDeep<ItemType, Options>
|
68 | : T extends ReadonlyMap<infer KeyType, infer ValueType>
|
69 | ? PartialReadonlyMapDeep<KeyType, ValueType, Options>
|
70 | : T extends ReadonlySet<infer ItemType>
|
71 | ? PartialReadonlySetDeep<ItemType, Options>
|
72 | : T extends object
|
73 | ? T extends ReadonlyArray<infer ItemType> // Test for arrays/tuples, per https://github.com/microsoft/TypeScript/issues/35156
|
74 | ? Options['recurseIntoArrays'] extends true
|
75 | ? ItemType[] extends T // Test for arrays (non-tuples) specifically
|
76 | ? readonly ItemType[] extends T // Differentiate readonly and mutable arrays
|
77 | ? ReadonlyArray<PartialDeep<ItemType | undefined, Options>>
|
78 | : Array<PartialDeep<ItemType | undefined, Options>>
|
79 | : PartialObjectDeep<T, Options> // Tuples behave properly
|
80 | : T // If they don't opt into array testing, just use the original type
|
81 | : PartialObjectDeep<T, Options>
|
82 | : unknown;
|
83 |
|
84 | /**
|
85 | Same as `PartialDeep`, but accepts only `Map`s and as inputs. Internal helper for `PartialDeep`.
|
86 | */
|
87 | type PartialMapDeep<KeyType, ValueType, Options extends PartialDeepOptions> = {} & Map<PartialDeep<KeyType, Options>, PartialDeep<ValueType, Options>>;
|
88 |
|
89 | /**
|
90 | Same as `PartialDeep`, but accepts only `Set`s as inputs. Internal helper for `PartialDeep`.
|
91 | */
|
92 | type PartialSetDeep<T, Options extends PartialDeepOptions> = {} & Set<PartialDeep<T, Options>>;
|
93 |
|
94 | /**
|
95 | Same as `PartialDeep`, but accepts only `ReadonlyMap`s as inputs. Internal helper for `PartialDeep`.
|
96 | */
|
97 | type PartialReadonlyMapDeep<KeyType, ValueType, Options extends PartialDeepOptions> = {} & ReadonlyMap<PartialDeep<KeyType, Options>, PartialDeep<ValueType, Options>>;
|
98 |
|
99 | /**
|
100 | Same as `PartialDeep`, but accepts only `ReadonlySet`s as inputs. Internal helper for `PartialDeep`.
|
101 | */
|
102 | type PartialReadonlySetDeep<T, Options extends PartialDeepOptions> = {} & ReadonlySet<PartialDeep<T, Options>>;
|
103 |
|
104 | /**
|
105 | Same as `PartialDeep`, but accepts only `object`s as inputs. Internal helper for `PartialDeep`.
|
106 | */
|
107 | type PartialObjectDeep<ObjectType extends object, Options extends PartialDeepOptions> = {
|
108 | [KeyType in keyof ObjectType]?: PartialDeep<ObjectType[KeyType], Options>
|
109 | };
|
110 |
|
\ | No newline at end of file |