Skip to content
Discussion options

You must be logged in to vote

Can you include a CodeSandbox example that explains what you are trying to accomplish?

If you only want to validate one of the input options, you can try using a Zod discriminated union.

const PhoneSchema = z.object({
  type: "phone",
  phone: z.string(),
});

const EmailSchema = z.object({
  type: "email",
  email: z.string().email(),
});

const FormSchema = z.discriminatedUnion("type", [PhoneSchema, EmailSchema]);

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@LikeDreamwalker
Comment options

Answer selected by LikeDreamwalker
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants