How to connect two zod scheme's?

28 views Asked by At

There are two schemes

they are in different files

You can somehow combine it according to the condition that if the isSurname field is selected, make the prevName/prevSurname fields mandatory and vice versa, or combine it according to the condition (I was looking in the direction of refine)

  const A = z.object({
    name: z.string(),
    surname: z.string(),
  });

  const B = z.object({
    isSurname: z.boolean(),
    prevName: z.string(),
    prevSurname: z.string(),
  });

  A.merge(B)
0

There are 0 answers