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
.required()
doesn't remove optional flag from the result of .nullish()
#1046
Comments
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. |
Up |
Here's how I solved it: https://github.com/3x071c/lsg/blob/e2a9592ba3ec5103556f2cf307c32f08aeaee32d/app/lib/util/zod.ts |
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. |
Up |
Having the same issue. I've opened a question here. |
Not quite, you removed Required is defined in typescript and in zod as being the opposite of Partial. So it should keep |
The (undocumented) function
.required
is not working properly for properties defined with.nullish()
:The resulting inferred type of
req
is:As you can see, all fields that were defined as
.optional()
have properly been made non-optional except for the one created using.nullish()
This seems to arise from the fact that
.nullish()
is defined to return aZodNullable<ZodOptional<T>>
and.required
simply returns the outermostZodOptional
without doing any type recursion, and as such it cannot see the optional in that type.The text was updated successfully, but these errors were encountered: