Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Support for Union Types #4

@derekparsons718

Description

@derekparsons718

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 here

The 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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions