1
|
|
|
//@ts-nocheck |
2
|
|
|
|
3
|
|
|
import { ClassHash } from "../../src/main.types" |
4
|
|
|
|
5
|
|
|
// type Excluder< |
6
|
|
|
// S extends Record<string, ClassHash>, |
7
|
|
|
// E extends {[K in keyof S]?: ClassHash} |
8
|
|
|
// > = { [P in Exclude<keyof S, keyof E>]: S[P]; } |
9
|
|
|
|
10
|
|
|
// interface Exclusion< |
11
|
|
|
// S extends Record<string, ClassHash> |
12
|
|
|
// > { |
13
|
|
|
// (source: S, ex: {[K in keyof S]?: ClassHash}): Excluder<S, typeof ex> |
14
|
|
|
// } |
15
|
|
|
|
16
|
|
|
function exclusion< |
17
|
|
|
S extends Record<string, ClassHash>, |
18
|
|
|
>( |
19
|
|
|
source: S, ex: {[K in keyof S]?: ClassHash} |
20
|
|
|
): typeof ex extends Record<infer E, any> |
21
|
|
|
? { [P in Exclude<keyof S, E>]: S[P]; } |
22
|
|
|
: never |
23
|
|
|
{ |
24
|
|
|
const $return = {...source} |
25
|
|
|
for (const k in ex) { |
26
|
|
|
delete $return[k] |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
//@ts-expect-error |
30
|
|
|
return $return |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
const source: Record<"a"|"b"|"c"|"d"|"e", ClassHash> = {a: "a", b: undefined, c: "c", d: undefined, e: undefined} |
34
|
|
|
|
35
|
|
|
const step0 = exclusion( |
36
|
|
|
source, |
37
|
|
|
//@ts-expect-error 'z' does not exist in type |
38
|
|
|
{z: undefined} |
39
|
|
|
) |
40
|
|
|
, answ0: typeof step0 = { |
41
|
|
|
//@ts-expect-error Type 'undefined' is not assignable to type 'never' |
42
|
|
|
whatever: undefined |
43
|
|
|
} |
44
|
|
|
, step1 = exclusion(source, {a: "a", b: undefined}) |
45
|
|
|
, step2 = exclusion(step1, {"c": undefined}) |
46
|
|
|
//@ts-expect-error Property 'd' is missing |
47
|
|
|
, answ |
48
|
|
|
: typeof step2 = { |
49
|
|
|
e: "", |
50
|
|
|
//@ts-expect-error Object literal may only specify known properties, and 'z' |
51
|
|
|
z: "" |
52
|
|
|
} |
53
|
|
|
export {step2, answ0} |