1 | import type {BuiltIns, HasMultipleCallSignatures} from './internal';
|
2 |
|
3 | type ExcludeUndefined<T> = Exclude<T, undefined>;
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
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 | export type RequiredDeep<T, E extends ExcludeUndefined<T> = ExcludeUndefined<T>> = E extends BuiltIns
|
47 | ? E
|
48 | : E extends Map<infer KeyType, infer ValueType>
|
49 | ? Map<RequiredDeep<KeyType>, RequiredDeep<ValueType>>
|
50 | : E extends Set<infer ItemType>
|
51 | ? Set<RequiredDeep<ItemType>>
|
52 | : E extends ReadonlyMap<infer KeyType, infer ValueType>
|
53 | ? ReadonlyMap<RequiredDeep<KeyType>, RequiredDeep<ValueType>>
|
54 | : E extends ReadonlySet<infer ItemType>
|
55 | ? ReadonlySet<RequiredDeep<ItemType>>
|
56 | : E extends WeakMap<infer KeyType, infer ValueType>
|
57 | ? WeakMap<RequiredDeep<KeyType>, RequiredDeep<ValueType>>
|
58 | : E extends WeakSet<infer ItemType>
|
59 | ? WeakSet<RequiredDeep<ItemType>>
|
60 | : E extends Promise<infer ValueType>
|
61 | ? Promise<RequiredDeep<ValueType>>
|
62 | : E extends (...arguments_: any[]) => unknown
|
63 | ? {} extends RequiredObjectDeep<E>
|
64 | ? E
|
65 | : HasMultipleCallSignatures<E> extends true
|
66 | ? E
|
67 | : ((...arguments_: Parameters<E>) => ReturnType<E>) & RequiredObjectDeep<E>
|
68 | : E extends object
|
69 | ? E extends Array<infer ItemType> // Test for arrays/tuples, per https://github.com/microsoft/TypeScript/issues/35156
|
70 | ? ItemType[] extends E // Test for arrays (non-tuples) specifically
|
71 | ? Array<RequiredDeep<ItemType>> // Recreate relevant array type to prevent eager evaluation of circular reference
|
72 | : RequiredObjectDeep<E> // Tuples behave properly
|
73 | : RequiredObjectDeep<E>
|
74 | : unknown;
|
75 |
|
76 | type RequiredObjectDeep<ObjectType extends object> = {
|
77 | [KeyType in keyof ObjectType]-?: RequiredDeep<ObjectType[KeyType]>
|
78 | };
|
79 |
|
\ | No newline at end of file |