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 | readonly allowUndefinedInNonTupleArrays?: boolean;
|
39 | };
|
40 |
|
41 |
|
42 |
|
43 |
|
44 |
|
45 |
|
46 |
|
47 |
|
48 |
|
49 |
|
50 |
|
51 |
|
52 |
|
53 |
|
54 |
|
55 |
|
56 |
|
57 |
|
58 |
|
59 |
|
60 |
|
61 |
|
62 |
|
63 |
|
64 |
|
65 |
|
66 |
|
67 |
|
68 |
|
69 |
|
70 |
|
71 |
|
72 |
|
73 |
|
74 |
|
75 |
|
76 |
|
77 |
|
78 |
|
79 |
|
80 |
|
81 |
|
82 |
|
83 |
|
84 |
|
85 |
|
86 |
|
87 |
|
88 |
|
89 |
|
90 | export type PartialDeep<T, Options extends PartialDeepOptions = {}> = T extends BuiltIns | (((...arguments_: any[]) => unknown)) | (new (...arguments_: any[]) => unknown)
|
91 | ? T
|
92 | : T extends Map<infer KeyType, infer ValueType>
|
93 | ? PartialMapDeep<KeyType, ValueType, Options>
|
94 | : T extends Set<infer ItemType>
|
95 | ? PartialSetDeep<ItemType, Options>
|
96 | : T extends ReadonlyMap<infer KeyType, infer ValueType>
|
97 | ? PartialReadonlyMapDeep<KeyType, ValueType, Options>
|
98 | : T extends ReadonlySet<infer ItemType>
|
99 | ? PartialReadonlySetDeep<ItemType, Options>
|
100 | : T extends object
|
101 | ? T extends ReadonlyArray<infer ItemType> // Test for arrays/tuples, per https://github.com/microsoft/TypeScript/issues/35156
|
102 | ? Options['recurseIntoArrays'] extends true
|
103 | ? ItemType[] extends T // Test for arrays (non-tuples) specifically
|
104 | ? readonly ItemType[] extends T // Differentiate readonly and mutable arrays
|
105 | ? ReadonlyArray<PartialDeep<Options['allowUndefinedInNonTupleArrays'] extends false ? ItemType : ItemType | undefined, Options>>
|
106 | : Array<PartialDeep<Options['allowUndefinedInNonTupleArrays'] extends false ? ItemType : ItemType | undefined, Options>>
|
107 | : PartialObjectDeep<T, Options> // Tuples behave properly
|
108 | : T // If they don't opt into array testing, just use the original type
|
109 | : PartialObjectDeep<T, Options>
|
110 | : unknown;
|
111 |
|
112 | /**
|
113 | Same as `PartialDeep`, but accepts only `Map`s and as inputs. Internal helper for `PartialDeep`.
|
114 | */
|
115 | type PartialMapDeep<KeyType, ValueType, Options extends PartialDeepOptions> = {} & Map<PartialDeep<KeyType, Options>, PartialDeep<ValueType, Options>>;
|
116 |
|
117 | /**
|
118 | Same as `PartialDeep`, but accepts only `Set`s as inputs. Internal helper for `PartialDeep`.
|
119 | */
|
120 | type PartialSetDeep<T, Options extends PartialDeepOptions> = {} & Set<PartialDeep<T, Options>>;
|
121 |
|
122 | /**
|
123 | Same as `PartialDeep`, but accepts only `ReadonlyMap`s as inputs. Internal helper for `PartialDeep`.
|
124 | */
|
125 | type PartialReadonlyMapDeep<KeyType, ValueType, Options extends PartialDeepOptions> = {} & ReadonlyMap<PartialDeep<KeyType, Options>, PartialDeep<ValueType, Options>>;
|
126 |
|
127 | /**
|
128 | Same as `PartialDeep`, but accepts only `ReadonlySet`s as inputs. Internal helper for `PartialDeep`.
|
129 | */
|
130 | type PartialReadonlySetDeep<T, Options extends PartialDeepOptions> = {} & ReadonlySet<PartialDeep<T, Options>>;
|
131 |
|
132 | /**
|
133 | Same as `PartialDeep`, but accepts only `object`s as inputs. Internal helper for `PartialDeep`.
|
134 | */
|
135 | type PartialObjectDeep<ObjectType extends object, Options extends PartialDeepOptions> = {
|
136 | [KeyType in keyof ObjectType]?: PartialDeep<ObjectType[KeyType], Options>
|
137 | };
|
138 |
|
\ | No newline at end of file |