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 | export type WritableDeep<T> = T extends BuiltIns
|
33 | ? T
|
34 | : T extends (...arguments_: any[]) => unknown
|
35 | ? {} extends WritableObjectDeep<T>
|
36 | ? T
|
37 | : HasMultipleCallSignatures<T> extends true
|
38 | ? T
|
39 | : ((...arguments_: Parameters<T>) => ReturnType<T>) & WritableObjectDeep<T>
|
40 | : T extends ReadonlyMap<unknown, unknown>
|
41 | ? WritableMapDeep<T>
|
42 | : T extends ReadonlySet<unknown>
|
43 | ? WritableSetDeep<T>
|
44 | : T extends readonly unknown[]
|
45 | ? WritableArrayDeep<T>
|
46 | : T extends object
|
47 | ? WritableObjectDeep<T>
|
48 | : unknown;
|
49 |
|
50 | /**
|
51 | Same as `WritableDeep`, but accepts only `Map`s as inputs. Internal helper for `WritableDeep`.
|
52 | */
|
53 | type WritableMapDeep<MapType extends ReadonlyMap<unknown, unknown>> =
|
54 | MapType extends ReadonlyMap<infer KeyType, infer ValueType>
|
55 | ? Map<WritableDeep<KeyType>, WritableDeep<ValueType>>
|
56 | : MapType; // Should not heppen
|
57 |
|
58 | /**
|
59 | Same as `WritableDeep`, but accepts only `Set`s as inputs. Internal helper for `WritableDeep`.
|
60 | */
|
61 | type WritableSetDeep<SetType extends ReadonlySet<unknown>> =
|
62 | SetType extends ReadonlySet<infer ItemType>
|
63 | ? Set<WritableDeep<ItemType>>
|
64 | : SetType; // Should not heppen
|
65 |
|
66 | /**
|
67 | Same as `WritableDeep`, but accepts only `object`s as inputs. Internal helper for `WritableDeep`.
|
68 | */
|
69 | type WritableObjectDeep<ObjectType extends object> = {
|
70 | -readonly [KeyType in keyof ObjectType]: WritableDeep<ObjectType[KeyType]>
|
71 | };
|
72 |
|
73 | /**
|
74 | Same as `WritableDeep`, but accepts only `Array`s as inputs. Internal helper for `WritableDeep`.
|
75 | */
|
76 | type WritableArrayDeep<ArrayType extends readonly unknown[]> =
|
77 | ArrayType extends readonly [] ? []
|
78 | : ArrayType extends readonly [...infer U, infer V] ? [...WritableArrayDeep<U>, WritableDeep<V>]
|
79 | : ArrayType extends readonly [infer U, ...infer V] ? [WritableDeep<U>, ...WritableArrayDeep<V>]
|
80 | : ArrayType extends ReadonlyArray<infer U> ? Array<WritableDeep<U>>
|
81 | : ArrayType extends Array<infer U> ? Array<WritableDeep<U>>
|
82 | : ArrayType;
|
83 |
|
84 |
|
\ | No newline at end of file |