1 | import type {ArraySplice} from './array-splice';
|
2 | import type {ExactKey, IsArrayReadonly, NonRecursiveType, SetArrayAccess, ToString} from './internal';
|
3 | import type {IsEqual} from './is-equal';
|
4 | import type {IsNever} from './is-never';
|
5 | import type {LiteralUnion} from './literal-union';
|
6 | import type {Paths} from './paths';
|
7 | import type {SharedUnionFieldsDeep} from './shared-union-fields-deep';
|
8 | import type {SimplifyDeep} from './simplify-deep';
|
9 | import type {UnknownArray} from './unknown-array';
|
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 |
|
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 |
|
91 |
|
92 |
|
93 | export type OmitDeep<T, PathUnion extends LiteralUnion<Paths<T>, string>> =
|
94 | SimplifyDeep<
|
95 | SharedUnionFieldsDeep<
|
96 | {[P in PathUnion]: OmitDeepWithOnePath<T, P>}[PathUnion]
|
97 | >,
|
98 | UnknownArray>;
|
99 |
|
100 |
|
101 |
|
102 |
|
103 | type OmitDeepWithOnePath<T, Path extends string | number> =
|
104 | T extends NonRecursiveType
|
105 | ? T
|
106 | : T extends UnknownArray ? SetArrayAccess<OmitDeepArrayWithOnePath<T, Path>, IsArrayReadonly<T>>
|
107 | : T extends object ? OmitDeepObjectWithOnePath<T, Path>
|
108 | : T;
|
109 |
|
110 |
|
111 |
|
112 |
|
113 | type OmitDeepObjectWithOnePath<ObjectT extends object, P extends string | number> =
|
114 | P extends `${infer RecordKeyInPath}.${infer SubPath}`
|
115 | ? {
|
116 | [Key in keyof ObjectT]:
|
117 | IsEqual<RecordKeyInPath, ToString<Key>> extends true
|
118 | ? ExactKey<ObjectT, Key> extends infer RealKey
|
119 | ? RealKey extends keyof ObjectT
|
120 | ? OmitDeepWithOnePath<ObjectT[RealKey], SubPath>
|
121 | : ObjectT[Key]
|
122 | : ObjectT[Key]
|
123 | : ObjectT[Key]
|
124 | }
|
125 | : ExactKey<ObjectT, P> extends infer Key
|
126 | ? IsNever<Key> extends true
|
127 | ? ObjectT
|
128 | : Key extends PropertyKey
|
129 | ? Omit<ObjectT, Key>
|
130 | : ObjectT
|
131 | : ObjectT;
|
132 |
|
133 |
|
134 |
|
135 |
|
136 |
|
137 |
|
138 |
|
139 |
|
140 |
|
141 |
|
142 |
|
143 |
|
144 | type OmitDeepArrayWithOnePath<ArrayType extends UnknownArray, P extends string | number> =
|
145 |
|
146 | P extends `${infer ArrayIndex extends number}.${infer SubPath}`
|
147 |
|
148 | ? number extends ArrayIndex
|
149 | ? Array<OmitDeepWithOnePath<NonNullable<ArrayType[number]>, SubPath>>
|
150 |
|
151 | : ArraySplice<ArrayType, ArrayIndex, 1, [OmitDeepWithOnePath<NonNullable<ArrayType[ArrayIndex]>, SubPath>]>
|
152 |
|
153 | : P extends `${infer ArrayIndex extends number}`
|
154 |
|
155 | ? number extends ArrayIndex
|
156 | ? []
|
157 |
|
158 | : ArraySplice<ArrayType, ArrayIndex, 1, [unknown]>
|
159 | : ArrayType;
|