Passed
Push — main ( 953ffa...e37dd6 )
by Andrii
01:54
created

defs.test.ts ➔ RWithout   A

Complexity

Conditions 1

Size

Total Lines 1
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
dl 0
loc 1
rs 10
c 0
b 0
f 0
1
import {
2
  Component,
3
  // ReactElement
4
} from "react"
5
import type {
6
  ClassNamed,
7
  ClassHash,
8
  ReactRelated,
9
  GetProps,
10
  ClassNamesProperty
11
} from "./defs"
12
13
describe("ClassNamesProperty", () => {
14
  it("Free declaration", () => {
15
    type Props = ClassNamesProperty<{
16
      class1: ClassHash, class2: ClassHash
17
    }>
18
    const suites: Record<string, Props["classnames"]> = {
19
      "all setted": {
20
        class1: "class1",
21
        class2: undefined
22
      },
23
      "redundant": {
24
        class1: "class1",
25
        class2: undefined,
26
        //@ts-expect-error
27
        redundant: "redundant"
28
      },
29
      //@ts-expect-error
30
      "missed": {
31
        class1: "class1"
32
      },
33
      "wrong type": {
34
        class1: "class1",
35
        //@ts-expect-error
36
        class2: false
37
      }
38
    }
39
    expect(suites).toBeInstanceOf(Object)
40
  })
41
  it("Module based", () => {
42
    type CssModule = {
43
      App: ClassHash
44
      class1: ClassHash, class2: ClassHash
45
    }
46
47
    type Props = ClassNamesProperty<CssModule, {
48
      class1: ClassHash
49
      class2: ClassHash
50
      //TODO #12 Why no suggestion?
51
    }>
52
53
    type PropsWithWrong = ClassNamesProperty<CssModule,
54
      //@ts-expect-error
55
      {class3: ClassHash}
56
    >
57
    
58
    const suite4wrong: PropsWithWrong["classnames"] = {
59
        class3: undefined,
60
    },
61
    suite: Props["classnames"] = {
62
      class1: "class1",
63
      class2: undefined
64
    }
65
    expect({suite4wrong, suite}).toBeInstanceOf(Object)
66
  })
67
})
68
69
it.todo("ClassNamesFrom")
70
71
describe("ReactRelated", () => {
72
  type Getter<T extends ReactRelated> = GetProps<T>
73
74
  type Without = ClassNamed
75
  type Wrong = ClassNamed & {classnames: string}
76
  type Some = ClassNamed & {classnames: Record<string, ClassHash>}
77
  type Props = ClassNamed & {classnames: {class1: ClassHash; class2: ClassHash;}}
78
79
  it("Component", () => {
80
    class RWithout extends Component<Without> {};
81
    class RWrong extends Component<Wrong> {};
82
    class RSome extends Component<Some> {};
83
    class RProps extends Component<Props> {};
84
85
    //@ts-expect-error
86
    type x =
87
    | Getter<typeof RProps>
88
    //@ts-expect-error
89
    type Res =
90
    //@ts-expect-error
91
    | Getter<typeof RWithout>
92
    //@ts-expect-error
93
    | Getter<typeof RWrong> 
94
    //Consider @ts-expect-error
95
    | Getter<typeof RSome>
96
    | Getter<typeof RProps>
97
    
98
    expect(true).toBe(true)
99
  })
100
101
  it("Function", () => {
102
    function RWithout(_: Without) {return null};
103
    function RWrong(_: Wrong) {return null};
104
    function RSome(_: Some) {return null};
105
    function RProps(_: Props) {return null};
106
107
    // type RF = (props: {classnames: any}) => ReactElement<any, any> | null
108
109
    // const ch1: Props extends {classnames: any} ? true : false = true
110
    // const ch2: Parameters<typeof RProps>[0] extends {classnames: any} ? true : false = true
111
    // const ch3: Parameters<typeof RProps>[0] extends Parameters<RF>[0] ? true : false = true
112
113
    //@ts-expect-error
114
    type Res =
115
    //TODO @ts-expect-error
116
    | Getter<typeof RWithout>
117
    //TODO @ts-expect-error
118
    | Getter<typeof RWrong>
119
    //Consider @ts-expect-error 
120
    | Getter<typeof RSome>
121
    | Getter<typeof RProps>
122
    
123
    expect(true).toBe(true)
124
  })
125
126
127
})
128