-
-
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
[Suggestion] Instruct users to return z.NEVER
in .superRefine()
when providing a type predicate
#1704
Comments
Hi @zetaraku I'm guessing you suggest this out of experience :) Shouldn't be a big lift... |
Ah - I spoke too soon. There is a quality-of-life situation at play here, where by doing what you suggest we would have to ask users to provide a type parameter in the call, which makes it a bit awkward since you're just trying to refine your validated output. The reason being that if we expect the type signature to be On the other hand! We can add some runtime-validation to make sure that |
Hi, @maxArturo. I knew that the return type is necessary for the inferred refined type so I didn't recommend users to declare their refinement function as I only encourage users to return a By the way, |
Yes understood! It was a copy paste in haste.
Sounds good, if your suggestion is to update the docs I think it is an improvement. I'd welcome the PR! Thanks! |
I made the PR above to update the docs. |
As the validation result solely depends on whether
ctx.addIssue()
is called,zod/README.md
Line 1891 in ad43854
and the return value is only used to satisfy the type predicate and is always thrown away,
zod/src/types.ts
Lines 3821 to 3822 in c9e4ed4
to prevent users from accidentally forgetting to call
ctx.addIssue()
while returning a boolean value as described in the example,zod/README.md
Lines 1931 to 1945 in ad43854
instructing users to return
z.NEVER
instead of a boolean at the end (indicating the value is never used) just like the early return case when providing a type predicate may be a good idea.The text was updated successfully, but these errors were encountered: