Passed
Push — main ( 67f6a3...fa9d82 )
by Andrii
02:11
created

src/sandbox/straight.ts   A

Complexity

Total Complexity 2
Complexity/F 2

Size

Lines of Code 40
Function Count 1

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 2
eloc 23
mnd 1
bc 1
fnc 1
dl 0
loc 40
rs 10
bpm 1
cpm 2
noi 0
c 0
b 0
f 0

1 Function

Rating   Name   Duplication   Size   Complexity  
A straight.ts ➔ exclusion 0 27 2
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}