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