src/react-swiss.test.ts   A
last analyzed

Complexity

Total Complexity 4
Complexity/F 1

Size

Lines of Code 70
Function Count 4

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 4
eloc 51
mnd 0
bc 0
fnc 4
dl 0
loc 70
bpm 0
cpm 1
noi 0
c 0
b 0
f 0
rs 10

4 Functions

Rating   Name   Duplication   Size   Complexity  
A react-swiss.test.ts ➔ RSome 0 1 1
A react-swiss.test.ts ➔ RWithout 0 1 1
A react-swiss.test.ts ➔ RProps 0 1 1
A react-swiss.test.ts ➔ RWrong 0 1 1
1
import {
2
  Component
3
} from "react"
4
import type {
5
  ClassNamed,
6
  ClassHash,
7
} from "./main.types"
8
import type {
9
  ReactRelated,
10
} from "./definitions.types"
11
import type {
12
  GetProps
13
} from "./react-swiss.types"
14
15
describe("ReactRelated", () => {
16
  type Getter<T extends ReactRelated> = GetProps<T>
17
18
  type Without = ClassNamed
19
  type Wrong = ClassNamed & {classnames: string}
20
  type Some = ClassNamed & {classnames: Record<string, ClassHash>}
21
  type Props = ClassNamed & {classnames: {class1: ClassHash; class2: ClassHash;}}
22
23
  it("Component", () => {
24
    class RWithout extends Component<Without> {};
25
    class RWrong extends Component<Wrong> {};
26
    class RSome extends Component<Some> {};
27
    class RProps extends Component<Props> {};
28
29
    //@ts-expect-error
30
    type x =
31
    | Getter<typeof RProps>
32
    //@ts-expect-error
33
    type Res =
34
    //@ts-expect-error
35
    | Getter<typeof RWithout>
36
    //@ts-expect-error
37
    | Getter<typeof RWrong>
38
    //Consider @ts-expect-error
39
    | Getter<typeof RSome>
40
    | Getter<typeof RProps>
41
42
    expect(true).toBe(true)
43
  })
44
45
  it("Function", () => {
46
    function RWithout(_: Without) {return null};
47
    function RWrong(_: Wrong) {return null};
48
    function RSome(_: Some) {return null};
49
    function RProps(_: Props) {return null};
50
51
    // type RF = (props: {classnames: any}) => ReactElement<any, any> | null
52
53
    // const ch1: Props extends {classnames: any} ? true : false = true
54
    // const ch2: Parameters<typeof RProps>[0] extends {classnames: any} ? true : false = true
55
    // const ch3: Parameters<typeof RProps>[0] extends Parameters<RF>[0] ? true : false = true
56
57
    //@ts-expect-error
58
    type Res =
59
    //TODO @ts-expect-error
60
    | Getter<typeof RWithout>
61
    //TODO @ts-expect-error
62
    | Getter<typeof RWrong>
63
    //Consider @ts-expect-error
64
    | Getter<typeof RSome>
65
    | Getter<typeof RProps>
66
67
    expect(true).toBe(true)
68
  })
69
})
70