__sandbox__/omitters/-infer.ts   A
last analyzed

Complexity

Total Complexity 2
Complexity/F 2

Size

Lines of Code 53
Function Count 1

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

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

1 Function

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