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 | export type OmitDeep<T, PathUnion extends LiteralUnion<Paths<T>, string>> =
|
75 | SimplifyDeep<
|
76 | SharedUnionFieldsDeep<
|
77 | {[P in PathUnion]: OmitDeepWithOnePath<T, P>}[PathUnion]
|
78 | >,
|
79 | UnknownArray>;
|
80 |
|
81 |
|
82 |
|
83 |
|
84 | type OmitDeepWithOnePath<T, Path extends string | number> =
|
85 | T extends NonRecursiveType
|
86 | ? T
|
87 | : T extends UnknownArray ? SetArrayAccess<OmitDeepArrayWithOnePath<T, Path>, IsArrayReadonly<T>>
|
88 | : T extends object ? OmitDeepObjectWithOnePath<T, Path>
|
89 | : T;
|
90 |
|
91 |
|
92 |
|
93 |
|
94 | type OmitDeepObjectWithOnePath<ObjectT extends object, P extends string | number> =
|
95 | P extends `${infer RecordKeyInPath}.${infer SubPath}`
|
96 | ? {
|
97 | [Key in keyof ObjectT]:
|
98 | IsEqual<RecordKeyInPath, ToString<Key>> extends true
|
99 | ? ExactKey<ObjectT, Key> extends infer RealKey
|
100 | ? RealKey extends keyof ObjectT
|
101 | ? OmitDeepWithOnePath<ObjectT[RealKey], SubPath>
|
102 | : ObjectT[Key]
|
103 | : ObjectT[Key]
|
104 | : ObjectT[Key]
|
105 | }
|
106 | : ExactKey<ObjectT, P> extends infer Key
|
107 | ? IsNever<Key> extends true
|
108 | ? ObjectT
|
109 | : Key extends PropertyKey
|
110 | ? Omit<ObjectT, Key>
|
111 | : ObjectT
|
112 | : ObjectT;
|
113 |
|
114 |
|
115 |
|
116 |
|
117 |
|
118 |
|
119 |
|
120 |
|
121 |
|
122 |
|
123 |
|
124 |
|
125 | type OmitDeepArrayWithOnePath<ArrayType extends UnknownArray, P extends string | number> =
|
126 |
|
127 | P extends `${infer ArrayIndex extends number}.${infer SubPath}`
|
128 |
|
129 | ? number extends ArrayIndex
|
130 | ? Array<OmitDeepWithOnePath<NonNullable<ArrayType[number]>, SubPath>>
|
131 |
|
132 | : ArraySplice<ArrayType, ArrayIndex, 1, [OmitDeepWithOnePath<NonNullable<ArrayType[ArrayIndex]>, SubPath>]>
|
133 |
|
134 | : P extends `${infer ArrayIndex extends number}`
|
135 |
|
136 | ? number extends ArrayIndex
|
137 | ? []
|
138 |
|
139 | : ArraySplice<ArrayType, ArrayIndex, 1, [unknown]>
|
140 | : ArrayType;
|