File tree Expand file tree Collapse file tree 2 files changed +23
-2
lines changed
packages/convex-helpers/server Expand file tree Collapse file tree 2 files changed +23
-2
lines changed Original file line number Diff line number Diff line change @@ -827,6 +827,10 @@ test("convexToZod complex types", () => {
827
827
828
828
const unionValidator = convexToZod ( v . union ( v . string ( ) , v . number ( ) ) ) ;
829
829
expect ( unionValidator . constructor . name ) . toBe ( "ZodUnion" ) ;
830
+ expect ( unionValidator . options [ 0 ] . constructor . name ) . toBe ( "ZodString" ) ;
831
+ expect ( unionValidator . options [ 1 ] . constructor . name ) . toBe ( "ZodNumber" ) ;
832
+ expectTypeOf ( unionValidator . options [ 0 ] ) . toEqualTypeOf < z . ZodString > ( ) ;
833
+ expectTypeOf ( unionValidator . options [ 1 ] ) . toEqualTypeOf < z . ZodNumber > ( ) ;
830
834
831
835
const literalValidator = convexToZod ( v . literal ( "hi" ) ) ;
832
836
expect ( literalValidator . constructor . name ) . toBe ( "ZodLiteral" ) ;
Original file line number Diff line number Diff line change @@ -1364,9 +1364,26 @@ type ZodFromValidatorBase<V extends GenericValidator> =
1364
1364
: z . ZodRecord < z . ZodString , ZodValidatorFromConvex < Value > >
1365
1365
: V extends VArray < any , any >
1366
1366
? z . ZodArray < ZodValidatorFromConvex < V [ "element" ] > >
1367
- : V extends VUnion < any , any , any , any >
1367
+ : V extends VUnion <
1368
+ any ,
1369
+ [
1370
+ infer A extends GenericValidator ,
1371
+ infer B extends GenericValidator ,
1372
+ ...infer Rest extends GenericValidator [ ] ,
1373
+ ] ,
1374
+ any ,
1375
+ any
1376
+ >
1368
1377
? z . ZodUnion <
1369
- [ ZodValidatorFromConvex < V [ "members" ] [ number ] > ]
1378
+ [
1379
+ ZodValidatorFromConvex < A > ,
1380
+ ZodValidatorFromConvex < B > ,
1381
+ ...{
1382
+ [ K in keyof Rest ] : ZodValidatorFromConvex <
1383
+ Rest [ K ]
1384
+ > ;
1385
+ } ,
1386
+ ]
1370
1387
>
1371
1388
: z . ZodTypeAny ; // fallback for unknown validators
1372
1389
You can’t perform that action at this time.
0 commit comments