-
-
Couldn't load subscription status.
- Fork 7
Open
Description
Union types appear not to work as expected.
Example:
interface A {
a: number
}
interface B {
b: string
}
type C = A | B;
const aSchema: toZod<A> = z.object({a: z.number()})
const bSchema: toZod<B> = z.object({b: z.string()})
const cSchema: toZod<C> = z.union([aSchema, bSchema]) //Error hereThe above code causes this error:
Type 'ZodUnion<[ZodObject<{ a: ZodNumber; }, "passthrough", ZodTypeAny, A, A>, ZodObject<{ b: ZodString; }, "passthrough", ZodTypeAny, B, B>]>' is missing the following properties from type 'ZodObject<{ a: ZodNumber; } | { b: ZodString; }, "passthrough", ZodTypeAny, C, C>': _shape, _unknownKeys, _catchall, shape, and 15 more. ts(2740)
Is there a workaround for this? And is there any plan to support this kind of code in the future?
boredland
Metadata
Metadata
Assignees
Labels
No labels