zod
zod copied to clipboard
DiscriminatedUnion not working with nested form names
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.
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.