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