-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Proposal: z.not(parser) or equivalent #2862
Comments
I think this could be useful. The typescript equivalent would be doing a z.not(z.string().email()) There should be a smart way to write your own utility function that replicates the behavior of |
It's a nice idea, but there's no way to represent these "NOT" types in TypeScript so it isn't likely. It's important that Zod's inferred types accurately reflect what will pass validation. The closest thing that I'd be willing to introduce is an Then you could do something like |
@colinhacks I think the |
…in schema validation colinhacks#2862
I've submitted a PR to add support for type negation using z.not() and the .not() method in schema validation. |
Purpose:
Returns the inverse of the parser that is passed. For example:
Would this be useful? Is there a way of doing this in standard
zod
that I'm missing?I know I can use
refine()
, but the ergonomics there are a bit awkward:The text was updated successfully, but these errors were encountered: