File tree Expand file tree Collapse file tree 2 files changed +4
-6
lines changed
Expand file tree Collapse file tree 2 files changed +4
-6
lines changed Original file line number Diff line number Diff line change @@ -206,8 +206,9 @@ export function list<
206206 * ```
207207 */
208208export function variant <
209- Props ,
210209 CaseType extends string ,
210+ Cases extends Record < CaseType , ComponentType < any > > ,
211+ Props extends ComponentProps < Cases [ CaseType ] > ,
211212 // It is ok here - it fixed bunch of type inference issues, when `bind` is not provided
212213 // but it is not clear why it works this way - Record<string, never> or any option other than `{}` doesn't work
213214 // eslint-disable-next-line @typescript-eslint/ban-types
@@ -216,7 +217,7 @@ export function variant<
216217 config :
217218 | {
218219 source : Store < CaseType > ;
219- cases : Partial < Record < CaseType , ComponentType < Props > > > ;
220+ cases : Partial < Cases > ;
220221 default ?: ComponentType < Props > ;
221222 bind ?: Bind ;
222223 hooks ?: Hooks < Props > ;
Original file line number Diff line number Diff line change @@ -34,7 +34,7 @@ import { expectType } from 'tsd';
3434 expectType < React . FC > ( VariableInput ) ;
3535}
3636
37- // variant catches incompatible props between cases
37+ // variant allows to pass incompatible props between cases - resulting component will have union of all props from all cases
3838{
3939 const Input : React . FC < {
4040 value : string ;
@@ -56,7 +56,6 @@ import { expectType } from 'tsd';
5656 } ,
5757 cases : {
5858 input : Input ,
59- // @ts -expect-error
6059 datetime : DateTime ,
6160 } ,
6261 } ) ;
@@ -264,7 +263,6 @@ import { expectType } from 'tsd';
264263 } ,
265264 cases : {
266265 button : Button < 'button' > ,
267- // @ts -expect-error
268266 a : Button < 'a' > ,
269267 } ,
270268 } ) ;
@@ -277,7 +275,6 @@ import { expectType } from 'tsd';
277275 } ,
278276 cases : {
279277 button : Button < 'button' > ,
280- // @ts -expect-error
281278 a : Button < 'a' > ,
282279 } ,
283280 } ) ;
You can’t perform that action at this time.
0 commit comments