const schema = z.object({
fName: z.string(),
lName: z.string(),
})
export default z.discriminatedUnion('hasAddress', [
schema.extend({
hasAddress: z.literal(false),
address: z.string().optional(),
}),
schema.extend({
hasAddress: z.literal(true),
address: z.string(),
}),
]);
Попробую завтра, спасибо!