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