__sandbox__/omitters/pipe-with-left.ts   A
last analyzed

Complexity

Total Complexity 3
Complexity/F 3

Size

Lines of Code 102
Function Count 1

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

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

1 Function

Rating   Name   Duplication   Size   Complexity  
A pipe-with-left.ts ➔ exclusion 0 30 3
1
import { ClassHash } from "../../src/main.types"
2
3
type tExcluder<
4
  Source extends Record<string, ClassHash>,
5
  Left extends Record<string, ClassHash> = Source,
6
  Used extends Record<string, ClassHash> = Record<never, ClassHash>,
7
>
8
= (
9
  <
10
    // E extends
11
    E extends {[K in keyof Left]?: K extends keyof Used ? never : ClassHash}
12
  >(exclude: E) =>
13
  //  keyof E extends keyof S ?
14
   { [K in Exclude<keyof Left, keyof E>]: ClassHash; }
15
    & tExcluder<
16
      Source,
17
      { [P in Exclude<keyof Left, keyof E>]: P extends keyof Used ? never : ClassHash; },
18
      { [P in keyof Used | keyof E]: ClassHash; }
19
    >
20
  // : {[P in Exclude<keyof E, keyof S>]: never;}
21
);
22
23
24
function exclusion<
25
  S extends Record<string, ClassHash>,
26
  E extends {[K in keyof S]?: ClassHash}
27
>(
28
  source: S, ex: E
29
) {
30
31
  const filtered = {...source}
32
  for (const k in ex) {
33
    delete filtered[k]
34
  }
35
36
  const host = (
37
    e: { [P in Exclude<keyof S, keyof E>]?: ClassHash; }
38
  ) => exclusion(
39
    filtered as { [P in Exclude<keyof S, keyof E>]: ClassHash; },
40
    e
41
  )
42
43
  for (const key in filtered)
44
    //@ts-expect-error
45
    host[key]
46
    = filtered[key]
47
48
  return host as tExcluder<
49
    S,
50
    {[P in Exclude<keyof S, keyof E>]: ClassHash;},
51
    E
52
  >
53
}
54
55
const source: Record<"a"|"b"|"c"|"d"|"e", ClassHash> = {a: "a", b: undefined, c: "c", d: undefined, e: undefined}
56
57
const step0 = exclusion(
58
  source,
59
  //@ts-expect-error 'z' does not exist in type
60
  {z: undefined}
61
)
62
, answ0: typeof step0 = {
63
  //@ts-expect-error
64
  whatever: true
65
}
66
, step1 = exclusion(source, {a: "a", b: undefined})
67
68
//@ts-expect-error
69
step1({"c": undefined, "z": undefined})
70
()
71
72
const step2 = step1({"c": undefined})
73
//@ts-expect-error
74
, {c} = step2
75
, step3 = {...step2({
76
  //@ts-expect-error
77
  "z": ""
78
})}
79
, result = {...step2}
80
, checks: Record<string, typeof result> = {
81
  "output": {d: "", e: ""},
82
  "unknown": {
83
    //@ts-expect-error
84
    unknown: ""
85
  },
86
  //@ts-expect-error
87
  "lost": {
88
    d: ""
89
  },
90
  "previously ommited": {
91
    d: "", e: "",
92
    //@ts-expect-error
93
    a: ""
94
  }
95
}
96
97
const unknown0 = exclusion({} as Record<string, ClassHash>, {a: "a"})
98
//todo @ts-error
99
, unknown1 = unknown0({a: "a"})
100
101
export {answ0, step3, checks, unknown1}
102
103
// type Additinioze<A, T0, E = never> = {
104
//   [P in keyof A]: A[P] extends E ? T0 : A[P]
105
// }
106
// type Additional<K extends string, T1, T2, E = never> = Additinioze<AntiRecord<K, T2, true, E>, T1, E>
107
// type AntiRecord<R extends string, T, Strict extends boolean, E = never>
108
// = {[k: string]: T}
109
// & (
110
//   Strict extends true
111
//   ? {[k in R]: E }
112
//   : {[k in R]?: E }
113
// )
114