@@ -2,15 +2,75 @@ import {
22 Component ,
33 // ReactElement
44} from "react"
5- import type { ClassNamed , ClassHash , ReactRelated , GetProps } from "./defs"
5+ import type {
6+ ClassNamed ,
7+ ClassHash ,
8+ ReactRelated ,
9+ GetProps ,
10+ ClassNamesProperty
11+ } from "./defs"
612
7- export { }
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+ }
846
9- type Getter < T extends ReactRelated > = GetProps < T >
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+ } )
1068
1169it . todo ( "ClassNamesFrom" )
1270
1371describe ( "ReactRelated" , ( ) => {
72+ type Getter < T extends ReactRelated > = GetProps < T >
73+
1474 type Without = ClassNamed
1575 type Wrong = ClassNamed & { classnames : string }
1676 type Some = ClassNamed & { classnames : Record < string , ClassHash > }
@@ -64,4 +124,4 @@ describe("ReactRelated", () => {
64124 } )
65125
66126
67- } )
127+ } )
0 commit comments