1 | import type {BuiltIns, HasMultipleCallSignatures} from './internal';
|
2 |
|
3 |
|
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 | export type ReadonlyDeep<T> = T extends BuiltIns
|
40 | ? T
|
41 | : T extends new (...arguments_: any[]) => unknown
|
42 | ? T
|
43 | : T extends (...arguments_: any[]) => unknown
|
44 | ? {} extends ReadonlyObjectDeep<T>
|
45 | ? T
|
46 | : HasMultipleCallSignatures<T> extends true
|
47 | ? T
|
48 | : ((...arguments_: Parameters<T>) => ReturnType<T>) & ReadonlyObjectDeep<T>
|
49 | : T extends Readonly<ReadonlyMap<infer KeyType, infer ValueType>>
|
50 | ? ReadonlyMapDeep<KeyType, ValueType>
|
51 | : T extends Readonly<ReadonlySet<infer ItemType>>
|
52 | ? ReadonlySetDeep<ItemType>
|
53 | : // Identify tuples to avoid converting them to arrays inadvertently; special case `readonly [...never[]]`, as it emerges undesirably from recursive invocations of ReadonlyDeep below.
|
54 | T extends readonly [] | readonly [...never[]]
|
55 | ? readonly []
|
56 | : T extends readonly [infer U, ...infer V]
|
57 | ? readonly [ReadonlyDeep<U>, ...ReadonlyDeep<V>]
|
58 | : T extends readonly [...infer U, infer V]
|
59 | ? readonly [...ReadonlyDeep<U>, ReadonlyDeep<V>]
|
60 | : T extends ReadonlyArray<infer ItemType>
|
61 | ? ReadonlyArray<ReadonlyDeep<ItemType>>
|
62 | : T extends object
|
63 | ? ReadonlyObjectDeep<T>
|
64 | : unknown;
|
65 |
|
66 | /**
|
67 | Same as `ReadonlyDeep`, but accepts only `ReadonlyMap`s as inputs. Internal helper for `ReadonlyDeep`.
|
68 | */
|
69 | type ReadonlyMapDeep<KeyType, ValueType> = {} & Readonly<ReadonlyMap<ReadonlyDeep<KeyType>, ReadonlyDeep<ValueType>>>;
|
70 |
|
71 | /**
|
72 | Same as `ReadonlyDeep`, but accepts only `ReadonlySet`s as inputs. Internal helper for `ReadonlyDeep`.
|
73 | */
|
74 | type ReadonlySetDeep<ItemType> = {} & Readonly<ReadonlySet<ReadonlyDeep<ItemType>>>;
|
75 |
|
76 | /**
|
77 | Same as `ReadonlyDeep`, but accepts only `object`s as inputs. Internal helper for `ReadonlyDeep`.
|
78 | */
|
79 | type ReadonlyObjectDeep<ObjectType extends object> = {
|
80 | readonly [KeyType in keyof ObjectType]: ReadonlyDeep<ObjectType[KeyType]>
|
81 | };
|
82 |
|
\ | No newline at end of file |