@@ -5,8 +5,8 @@ import switchFunctional, {
55 type Switch ,
66} from 'switch-functional'
77
8- const switchStatement = switchFunctional ( true )
9- expectType < Switch > ( switchStatement )
8+ const switchStatement = switchFunctional ( true as const )
9+ expectAssignable < Switch > ( switchStatement )
1010
1111// @ts -expect-error
1212switchFunctional ( )
@@ -24,7 +24,10 @@ switchFunctional({} as const)
2424switchFunctional ( [ ] as const )
2525switchFunctional ( ( ) => { } )
2626
27- expectType < Switch > ( switchStatement . case ( true , true ) )
27+ const caseStatement = switchStatement . case ( true , 0 as const )
28+
29+ expectType < Switch < 0 , true > > ( switchStatement . case ( true , 0 ) )
30+ expectType < Switch < 0 | 1 , true > > ( caseStatement . case ( true , 1 ) )
2831
2932switchStatement . case ( 0 , true )
3033switchStatement . case ( 0n , true )
@@ -40,6 +43,22 @@ switchStatement.case([] as const, true)
4043switchStatement . case ( [ true ] as const , true )
4144switchStatement . case ( [ ( ) => '' ] as const , true )
4245switchStatement . case ( ( ) => true , true )
46+ switchStatement . case ( ( value : true ) => true , true )
47+ caseStatement . case ( 0 , true )
48+ caseStatement . case ( 0n , true )
49+ caseStatement . case ( true , true )
50+ caseStatement . case ( null , true )
51+ caseStatement . case ( undefined , true )
52+ caseStatement . case ( '' , true )
53+ caseStatement . case ( Symbol ( '' ) , true )
54+ caseStatement . case ( { } as const , true )
55+ caseStatement . case ( { a : true } as const , true )
56+ caseStatement . case ( { a : ( ) => '' } as const , true )
57+ caseStatement . case ( [ ] as const , true )
58+ caseStatement . case ( [ true ] as const , true )
59+ caseStatement . case ( [ ( ) => '' ] as const , true )
60+ caseStatement . case ( ( ) => true , true )
61+ caseStatement . case ( ( value : true ) => true , true )
4362expectAssignable < Condition > ( 0 )
4463expectAssignable < Condition > ( 0n )
4564expectAssignable < Condition > ( true )
@@ -54,10 +73,24 @@ expectAssignable<Condition>([] as const)
5473expectAssignable < Condition > ( [ true ] as const )
5574expectAssignable < Condition > ( [ ( ) => '' ] as const )
5675expectAssignable < Condition > ( ( ) => true )
76+ expectAssignable < Condition < true > > ( ( ) => true )
77+ expectAssignable < Condition < true > > ( ( value : true ) => true )
5778
5879// @ts -expect-error
5980switchStatement . case ( ( ) => '' , true )
81+ // @ts -expect-error
82+ switchStatement . case ( ( value : false ) => true , true )
83+ // @ts -expect-error
84+ switchStatement . case ( ( value : true , second : true ) => true , true )
85+ // @ts -expect-error
86+ caseStatement . case ( ( ) => '' , true )
87+ // @ts -expect-error
88+ caseStatement . case ( ( value : false ) => true , true )
89+ // @ts -expect-error
90+ caseStatement . case ( ( value : true , second : true ) => true , true )
6091expectNotAssignable < Condition > ( ( ) => '' )
92+ expectNotAssignable < Condition < true > > ( ( value : false ) => true )
93+ expectNotAssignable < Condition < true > > ( ( value : true , second : true ) => true )
6194
6295switchStatement . case ( true , 0 )
6396switchStatement . case ( true , 0n )
@@ -69,15 +102,39 @@ switchStatement.case(true, Symbol(''))
69102switchStatement . case ( true , { } as const )
70103switchStatement . case ( true , [ ] as const )
71104switchStatement . case ( true , ( ) => { } )
105+ switchStatement . case ( true , ( value : true ) => { } )
106+ caseStatement . case ( true , 0 )
107+ caseStatement . case ( true , 0n )
108+ caseStatement . case ( true , true )
109+ caseStatement . case ( true , null )
110+ caseStatement . case ( true , undefined )
111+ caseStatement . case ( true , '' )
112+ caseStatement . case ( true , Symbol ( '' ) )
113+ caseStatement . case ( true , { } as const )
114+ caseStatement . case ( true , [ ] as const )
115+ caseStatement . case ( true , ( ) => { } )
116+ caseStatement . case ( true , ( value : true ) => { } )
72117
73118// @ts -expect-error
74119switchStatement . case ( )
75120// @ts -expect-error
76121switchStatement . case ( true )
77122// @ts -expect-error
78123switchStatement . case ( true , true , true )
79-
80- expectAssignable < unknown > ( switchStatement . default ( true ) )
124+ // @ts -expect-error
125+ switchStatement . case ( true , ( value : false ) => { } )
126+ // @ts -expect-error
127+ switchStatement . case ( true , ( value : true , second : false ) => { } )
128+ // @ts -expect-error
129+ caseStatement . case ( )
130+ // @ts -expect-error
131+ caseStatement . case ( true )
132+ // @ts -expect-error
133+ caseStatement . case ( true , true , true )
134+ // @ts -expect-error
135+ caseStatement . case ( true , ( value : false ) => { } )
136+ // @ts -expect-error
137+ caseStatement . case ( true , ( value : true , second : false ) => { } )
81138
82139switchStatement . default ( 0 )
83140switchStatement . default ( 0n )
@@ -89,22 +146,56 @@ switchStatement.default(Symbol(''))
89146switchStatement . default ( { } as const )
90147switchStatement . default ( [ ] as const )
91148switchStatement . default ( ( ) => { } )
149+ switchStatement . default ( ( value : true ) => { } )
150+ caseStatement . default ( 0 )
151+ caseStatement . default ( 0n )
152+ caseStatement . default ( true )
153+ caseStatement . default ( null )
154+ caseStatement . default ( undefined )
155+ caseStatement . default ( '' )
156+ caseStatement . default ( Symbol ( '' ) )
157+ caseStatement . default ( { } as const )
158+ caseStatement . default ( [ ] as const )
159+ caseStatement . default ( ( ) => { } )
160+ caseStatement . default ( ( value : true ) => { } )
92161
93162// @ts -expect-error
94163switchStatement . default ( )
95164// @ts -expect-error
96165switchStatement . default ( true , true )
166+ // @ts -expect-error
167+ switchStatement . default ( ( value : false ) => { } )
168+ // @ts -expect-error
169+ switchStatement . default ( ( value : true , second : false ) => { } )
170+ // @ts -expect-error
171+ caseStatement . default ( )
172+ // @ts -expect-error
173+ caseStatement . default ( true , true )
174+ // @ts -expect-error
175+ caseStatement . default ( ( value : false ) => { } )
176+ // @ts -expect-error
177+ caseStatement . default ( ( value : true , second : false ) => { } )
97178
98179// @ts -expect-error
99180// eslint-disable-next-line @typescript-eslint/no-unsafe-call
100181switchStatement . other ( )
182+ // @ts -expect-error
183+ // eslint-disable-next-line @typescript-eslint/no-unsafe-call
184+ caseStatement . other ( )
101185
102186expectType < 1 > ( switchStatement . default ( 1 as const ) )
103- expectType < 1 | 2 > ( switchStatement . case ( true , 2 as const ) . default ( 1 as const ) )
187+ expectType < 1 | 2 > ( switchStatement . case ( true , 1 as const ) . default ( 2 as const ) )
188+ expectType < 0 | 1 > ( caseStatement . default ( 1 as const ) )
189+ expectType < 0 | 1 | 2 > ( caseStatement . case ( true , 1 as const ) . default ( 2 as const ) )
104190
105- expectType < Switch < 1 > > ( switchStatement . case ( true , 1 as const ) )
106- expectType < Switch < 1 | 2 > > (
191+ expectType < Switch < 1 , true > > ( switchStatement . case ( true , 1 as const ) )
192+ expectType < Switch < 1 | 2 , true > > (
107193 switchStatement . case ( true , 1 as const ) . case ( true , 2 as const ) ,
108194)
195+ expectType < Switch < 0 | 1 , true > > ( caseStatement . case ( true , 1 as const ) )
196+ expectType < Switch < 0 | 1 | 2 , true > > (
197+ caseStatement . case ( true , 1 as const ) . case ( true , 2 as const ) ,
198+ )
109199
110- expectAssignable < Switch < 1 | 2 > > ( switchStatement . case ( true , 1 as const ) )
200+ expectAssignable < Switch < 1 | 2 , true > > ( switchStatement . case ( true , 1 as const ) )
201+ expectAssignable < Switch < 0 | 1 | 2 , true > > ( caseStatement . case ( true , 1 as const ) )
0 commit comments