forked from ts-essentials/ts-essentials
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.ts
46 lines (45 loc) · 1.58 KB
/
index.ts
1
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
40
41
42
43
44
45
46
import { AnyRecord } from "../any-record";
import { Builtin } from "../built-in";
export type DeepOmit<Type, Filter> = Type extends Builtin
? Type
: Type extends Map<infer Keys, infer Values>
? Filter extends Map<Keys, infer FilterValues>
? Map<Keys, DeepOmit<Values, FilterValues>>
: Type
: Type extends ReadonlyMap<infer Keys, infer Values>
? Filter extends ReadonlyMap<Keys, infer FilterValues>
? ReadonlyMap<Keys, DeepOmit<Values, FilterValues>>
: Type
: Type extends WeakMap<infer Keys, infer Values>
? Filter extends WeakMap<Keys, infer FilterValues>
? WeakMap<Keys, DeepOmit<Values, FilterValues>>
: Type
: Type extends Set<infer Values>
? Filter extends Set<infer FilterValues>
? Set<DeepOmit<Values, FilterValues>>
: Type
: Type extends ReadonlySet<infer Values>
? Filter extends ReadonlySet<infer FilterValues>
? ReadonlySet<DeepOmit<Values, FilterValues>>
: Type
: Type extends WeakSet<infer Values>
? Filter extends WeakSet<infer FilterValues>
? WeakSet<DeepOmit<Values, FilterValues>>
: Type
: Type extends Array<infer Values>
? Filter extends Array<infer FilterValues>
? Array<DeepOmit<Values, FilterValues>>
: Type
: Type extends Promise<infer Value>
? Filter extends Promise<infer FilterValue>
? Promise<DeepOmit<Value, FilterValue>>
: Type
: Filter extends AnyRecord
? {
[Key in keyof Type as Key extends keyof Filter
? Filter[Key] extends true
? never
: Key
: Key]: Key extends keyof Filter ? DeepOmit<Type[Key], Filter[Key]> : Type[Key];
}
: never;