#How can I use zod discriminated union for search params?
9 messages · Page 1 of 1 (latest)
what did you try?
I've tried this and variations to this, like using undefined instead of never but I always get ts error either in <Link> components or in loader search params
const schema = z.discriminatedUnion('mode', [
z.object({
mode: z.literal('schedule-appointment'),
slot_id: z.string(),
start_date: z.string().datetime(),
end_date: z.string().datetime(),
appointment_code: z.string(),
zip: z.string().max(10),
}),
z.object({
mode: z.enum(['request-appointment', 'manual-booking']),
slot_id: z.never(),
start_date: z.never(),
end_date: z.never(),
appointment_code: z.never(),
zip: z.string().max(10),
}),
]);
If this is not enough I can try to provide an example during the weekend. It's so time consuming to construct an example 😄
really, why is it so hard to create an example?
just fork a stackblitz router example
and modify it