-
-
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
Using undefined() incorrectly marks keys as optional #2464
Comments
@AndrewRayCode what is expected to resolve this issue? |
@kemilbeltre There is a hack you can use in the linked Stackoverflow question. I couldn't use that for my app so I sadly had to refactor my core domain types to make the key optional. Zod doesn't seem to handle undefined types correctly which is ironic considering the author says Zod is better at type inference than Yup:
There seems to be something fundamentally wrong with Zod, because this doesn't work either: const stringOrUndefined = z.custom<string | undefined>(
(v) => typeof v === 'string' || v === undefined
);
const mySchema = z.object({ field: stringOrUndefined });
type Schema = z.infer<typeof mySchema>; Results in
|
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. |
Doesn't seem stale given the reports (stackoverflow, this report, and #2598) |
From this Stackoverflow question (I'm hitting the same thing):
This code:
Produces a schema with an optional key:
Same with:
Same with any variation of union (which seems to be how
.or()
resolves under the hood anyway)The text was updated successfully, but these errors were encountered: