-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Tuples in unions does not get validated since v3.9.1 #668
Comments
I have a similar issue, the I only just moved from Here are some examples: const BrokenSchema = z.union([
z.object({
email: z.string().email(),
}),
z.object({
email: z.literal(null),
}),
]);
// same as above
const BrokenSchema2 = z
.object({
email: z.string().email(),
})
.or(
z.object({
email: z.literal(null),
}),
);
const res1 = BrokenSchema.safeParse({ email: 'asdf' });
expect(res1.success).toBe(false); // this test DOES NOT pass
const res2 = BrokenSchema.safeParse({ email: 9 });
expect(res2.success).toBe(false); // this test DOES pass |
I'll look into this today. |
Here's another repro that fails (as expected) in 3.8.2 and succeeds in 3.9.0: const schema = z.union([z.string().refine(() => false), z.number().refine(() => false)]);
console.log('result is', schema.parse('asdf')); |
Should be fixed in 3.9.2+ |
Thanks @colinhacks, for us the case that @oleg-codaio presented still doesn't work (in 3.9.4).
|
Yes, running v3.9.5, this is an issue for us at Deletype as well. It seems any union that includes a string with a refiner attached (like ohana54's example) just doesn't work. Here is what is failing for us: z.union([
z.number(),
z.string().refine(val => !isNaN(Number(val)))
]) |
Oops looks like I failed to fully roll back the changes that caused this error. I've confirmed that all the above cases are working in Zod v3.9.8+. |
Thanks! Hopefully there are unit tests too to help catch any future regressions. (happy to help contribute some if not quite yet.) |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
Following schema
failed before
v3.9.1
with following databut since
v3.9.1
zod
does not validate the-60
value anymore as.nonnegative()
. Parsing is always successful whereas beforev3.9.1
it failed (which is the expected behaviour)The text was updated successfully, but these errors were encountered: