Skip to content
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

strict() on zod objects within union #17

Merged
merged 1 commit into from
Sep 4, 2022
Merged

strict() on zod objects within union #17

merged 1 commit into from
Sep 4, 2022

Conversation

kristinlindquist
Copy link
Contributor

Description

Adding '.strict()' to the Zod objects within a union type, which appears to keep Zod from stripping properties via non-matching elements of the union.

Not sure if there are reasons to avoid strict here. If so, this PR may not be an appropriate solution for the problem. Additionally, this seems like questionable behavior on Zod's part and thus the "real fix" may be within Zod.

References

Fixes #16

@omar-dulaimi
Copy link
Owner

Thank you for the PR @kristinlindquist
I tested it both as a schema and through tRPC context, haven't faced any problems with it. The docs of Zod say that this method only disallows unrecognized keys, by throwing an error. I think this behavior is caused due to the recursive types we generate.

At any rate, this solution works for now. Until further research.

@omar-dulaimi omar-dulaimi self-assigned this Sep 4, 2022
@omar-dulaimi omar-dulaimi added the bug Something isn't working label Sep 4, 2022
@omar-dulaimi omar-dulaimi merged commit 2de3462 into omar-dulaimi:master Sep 4, 2022
BitPhoenix pushed a commit to BitPhoenix/prisma-zod-generator that referenced this pull request Oct 28, 2022
…trict-on-zod-within-union

strict() on zod objects within union
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Optional typing in unions strips all properties
2 participants