Open aaalloc opened 5 months ago
It's passing because your payload is valid against the first object in the union. You could fix this by enforcing strict objects
It's passing because your payload is valid against the first object in the union. You could fix this by enforcing strict objects
But why in the first section type2 is ignored ?
Because it successfully validated against the first object.
Zod will test the input against each of the "options" in order and return the first value that validates successfully.
Hi,
Basically, when doing zod objects and doing an union on that, when the second object of the union has optional fields, parsing just ignore it ! Is that normal ? I can't find any information about that. I've came with a solution using discriminatedUnion but that feels a little bit dirty ...
I've created a reproduction environment for replaying the issue
https://stackblitz.com/edit/typescript-f8ppcz?file=schemas%2FschemaWithDefaultType.ts