| Total Complexity | 2 |
| Complexity/F | 2 |
| Lines of Code | 40 |
| 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 | E extends Record<string, ClassValue>, |
||
| 18 | S extends E |
||
| 19 | // S extends Record<string, ClassValue>, |
||
| 20 | // E extends {[K in keyof S]?: ClassValue} |
||
| 21 | >( |
||
| 22 | source: S, ex: E |
||
| 23 | ): { [P in Exclude<keyof S, keyof E>]: S[P]; } |
||
| 24 | { |
||
| 25 | const $return = {...source} |
||
| 26 | for (const k in ex) { |
||
| 27 | delete $return[k] |
||
| 28 | } |
||
| 29 | |||
| 30 | return $return |
||
| 31 | } |
||
| 32 | |||
| 33 | const source: Record<"a"|"b"|"c"|"d", ClassValue> = {a: "a", b: undefined, c: "c", d: undefined} |
||
| 34 | , p1: Record<"a"|"b", ClassValue> = {a: "a", b: undefined} |
||
| 35 | , p2: Record<"c", ClassValue> = {"c": undefined} |
||
| 36 | |||
| 37 | const step1 = exclusion(source, p1) |
||
| 38 | , step2 = exclusion(step1, p2) |
||
| 39 | |||
| 40 | export {step2} |