@@ -108,7 +108,7 @@ export type RecipeVariants<RecipeFn extends RuntimeFn<VariantGroups>> =
108
108
109
109
// == Tests ====================================================================
110
110
if ( import . meta. vitest ) {
111
- const { describe, it, assertType } = import . meta. vitest ;
111
+ const { describe, it, assertType, expectTypeOf } = import . meta. vitest ;
112
112
113
113
describe . concurrent ( "ConditionVariants Type Test" , ( ) => {
114
114
it ( "Conditional Type" , ( ) => {
@@ -239,6 +239,59 @@ if (import.meta.vitest) {
239
239
} ) ;
240
240
} ) ;
241
241
242
+ describe . concurrent ( "RuntimeFn Type Test" , ( ) => {
243
+ type TestVariantsType = {
244
+ color : {
245
+ brand : { color : string } ;
246
+ accent : { color : string } ;
247
+ } ;
248
+ size : {
249
+ small : { padding : number } ;
250
+ medium : { padding : number } ;
251
+ large : { padding : number } ;
252
+ } ;
253
+ outlined : {
254
+ true : { border : string } ;
255
+ false : { border : string } ;
256
+ } ;
257
+ } ;
258
+
259
+ it ( "RuntimeFn Type Check" , ( ) => {
260
+ type ExpectedResultType = RuntimeFn < TestVariantsType > ;
261
+ expectTypeOf < ExpectedResultType > ( ) . toBeFunction ( ) ;
262
+ expectTypeOf < ExpectedResultType [ "variants" ] > ( ) . toBeFunction ( ) ;
263
+ expectTypeOf < ExpectedResultType [ "classNames" ] > ( ) . toBeObject ( ) ;
264
+
265
+ const expectedResult = Object . assign (
266
+ ( _options ?: ResolveComplex < VariantSelection < TestVariantsType > > ) =>
267
+ "my-class" ,
268
+ {
269
+ variants : ( ) =>
270
+ [ "color" , "size" , "outlined" ] satisfies ( keyof TestVariantsType ) [ ] ,
271
+ classNames : {
272
+ base : "basic-class" ,
273
+ variants : {
274
+ color : {
275
+ brand : "color-brand" ,
276
+ accent : "color-accent"
277
+ } ,
278
+ size : {
279
+ small : "size-small" ,
280
+ medium : "size-medium" ,
281
+ large : "size-large"
282
+ } ,
283
+ outlined : {
284
+ true : "outlined-true" ,
285
+ false : "outlined-false"
286
+ }
287
+ }
288
+ } satisfies RecipeClassNames < TestVariantsType >
289
+ }
290
+ ) ;
291
+ assertType < ExpectedResultType > ( expectedResult ) ;
292
+ } ) ;
293
+ } ) ;
294
+
242
295
describe . concurrent ( "Types related to Rules" , ( ) => {
243
296
function assertValidOptions <
244
297
Variants extends VariantGroups | undefined = undefined ,
0 commit comments