Skip to content

Commit 912327b

Browse files
committed
Merge branch 'Convex-Helper-Types-Fix'
2 parents 413ed45 + 0e799ef commit 912327b

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

packages/convex-helpers/server/zod.test.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -827,6 +827,10 @@ test("convexToZod complex types", () => {
827827

828828
const unionValidator = convexToZod(v.union(v.string(), v.number()));
829829
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>();
830834

831835
const literalValidator = convexToZod(v.literal("hi"));
832836
expect(literalValidator.constructor.name).toBe("ZodLiteral");

packages/convex-helpers/server/zod.ts

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1364,9 +1364,26 @@ type ZodFromValidatorBase<V extends GenericValidator> =
13641364
: z.ZodRecord<z.ZodString, ZodValidatorFromConvex<Value>>
13651365
: V extends VArray<any, any>
13661366
? 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+
>
13681377
? 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+
]
13701387
>
13711388
: z.ZodTypeAny; // fallback for unknown validators
13721389

0 commit comments

Comments
 (0)