zod icon indicating copy to clipboard operation
zod copied to clipboard

DiscriminatedUnion not working with nested form names

Open 0bon opened this issue 3 years ago • 1 comments

Lets say I have 2 inputs <input type="number" name="contact.type" /> <input type="text" name="contact.name" />

And a schema as follows:

const schema = z.object({
    contact: z.object({
        name: z.discriminatedUnion('contact.type', [
            z.object({
                type: z.literal(1),
                name: z.string().min(1),
            }),
            z.object({
                type: z.literal(2),
                name: z.string().min(2),
            })
        ],
    })
})

Zod complains about the 'contact.type' discriminationUnion not being assignable. It seems like it doesn't like the object notation, since changing all elements from contact.type to contacttype and updating schema fixed all these issue.

0bon avatar Sep 30 '22 16:09 0bon

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Nov 29 '22 20:11 stale[bot]