1
|
|
|
import { ClassValue } from "../../defs" |
2
|
|
|
|
3
|
|
|
export {} |
4
|
|
|
|
5
|
|
|
type tExcluder2< |
6
|
|
|
S extends Record<string, ClassValue>, |
7
|
|
|
U extends {[K in keyof S]?: ClassValue} |
8
|
|
|
> |
9
|
|
|
= ( |
10
|
|
|
<E extends {[K in Exclude<keyof S, U>]?: ClassValue}>(exclude: E) => |
11
|
|
|
// keyof E extends keyof S ? |
12
|
|
|
{ [P in Exclude<keyof S, keyof E | U>]: ClassValue; } |
13
|
|
|
& tExcluder2< |
14
|
|
|
S, |
15
|
|
|
{[K in keyof E | keyof U]: ClassValue} |
16
|
|
|
> |
17
|
|
|
// : {[P in Exclude<keyof E, keyof S>]: never;} |
18
|
|
|
); |
19
|
|
|
|
20
|
|
|
|
21
|
|
|
function exclusion< |
22
|
|
|
S extends Record<string, ClassValue>, |
23
|
|
|
E extends {[K in keyof S]?: ClassValue} |
24
|
|
|
>( |
25
|
|
|
source: S, ex: E |
26
|
|
|
) { |
27
|
|
|
|
28
|
|
|
const filtered = {...source} |
29
|
|
|
for (const k in ex) { |
30
|
|
|
delete filtered[k] |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
const host = ( |
34
|
|
|
e: { [P in Exclude<keyof S, keyof E>]?: ClassValue; } |
35
|
|
|
) => exclusion( |
36
|
|
|
filtered as { [P in Exclude<keyof S, keyof E>]: ClassValue; }, |
37
|
|
|
e |
38
|
|
|
) |
39
|
|
|
|
40
|
|
|
for (const key in filtered) |
41
|
|
|
//@ts-expect-error |
42
|
|
|
host[key] |
43
|
|
|
= filtered[key] |
44
|
|
|
|
45
|
|
|
return host as tExcluder2<S, {[K in keyof E]: ClassValue}> |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
const source: Record<"a"|"b"|"c"|"d"|"e", ClassValue> = {a: "a", b: undefined, c: "c", d: undefined, e: undefined} |
49
|
|
|
|
50
|
|
|
const step0 = exclusion( |
51
|
|
|
source, |
52
|
|
|
//@ts-expect-error 'z' does not exist in type |
53
|
|
|
{z: undefined} |
54
|
|
|
) |
55
|
|
|
, answ0: typeof step0 = { |
56
|
|
|
//@ts-expect-error |
57
|
|
|
whatever: true |
58
|
|
|
} |
59
|
|
|
, step1 = exclusion(source, {a: "a", b: undefined}) |
60
|
|
|
|
61
|
|
|
//@ts-expect-error |
62
|
|
|
step1({"c": undefined, "z": undefined}) |
63
|
|
|
() |
64
|
|
|
|
65
|
|
|
const step2 = step1({"c": undefined}) |
66
|
|
|
//@ts-expect-error |
67
|
|
|
, {c} = step2 |
68
|
|
|
, step3 = {...step2({ |
69
|
|
|
//@ts-expect-error |
70
|
|
|
"z": "" |
71
|
|
|
})} |
72
|
|
|
, result = {...step2} |
73
|
|
|
, checks: Record<string, typeof result> = { |
74
|
|
|
//@ts-expect-error //TODO |
75
|
|
|
"output": {d: "", e: ""}, |
76
|
|
|
"unknown": { |
77
|
|
|
//@ts-expect-error |
78
|
|
|
unknown: "" |
79
|
|
|
}, |
80
|
|
|
//@ts-expect-error |
81
|
|
|
"lost": { |
82
|
|
|
d: "" |
83
|
|
|
}, |
84
|
|
|
//@ts-expect-error //TODO |
85
|
|
|
"previously ommited": { |
86
|
|
|
d: "", e: "", |
87
|
|
|
//TODO @ts-expect-error |
88
|
|
|
a: "" |
89
|
|
|
} |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
export {answ0, step3, checks} |