Z
Zod7mo ago
Gludek

Gludek - Heey, can I somehow extend/merge discr...

Heey, can I somehow extend/merge discriminated union with object? my union
z
.discriminatedUnion('ssnMode', [
z.object({
ssnMode: z.literal('true'),
ssn: z.string(),
}),
z.object({
ssnMode: z.literal('false'),
passport: z.string(),
dob: z.date(),
}),
])
z
.discriminatedUnion('ssnMode', [
z.object({
ssnMode: z.literal('true'),
ssn: z.string(),
}),
z.object({
ssnMode: z.literal('false'),
passport: z.string(),
dob: z.date(),
}),
])
and object
z.object({
adult: z.boolean(),
patientName: z.string(),
patientSurname: z.string(),
patientPhone: z.string(),
patientEmail: z.string().optional(),
})
z.object({
adult: z.boolean(),
patientName: z.string(),
patientSurname: z.string(),
patientPhone: z.string(),
patientEmail: z.string().optional(),
})
Solution:
Not currently possible. There are work arounds though, but it requires you to redefine the union every time.
Jump to solution
3 Replies
Gludek
Gludek7mo ago
I can't use .and becasue I need to extend it later to add fields based on this object
Solution
Scott Trinh
Scott Trinh7mo ago
Not currently possible. There are work arounds though, but it requires you to redefine the union every time.
Gludek
Gludek7mo ago
oh well, then I'll probably nest the union then
Want results from more Discord servers?
Add your server