-
Notifications
You must be signed in to change notification settings - Fork 50
Zod V4 implementation #701
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
base: main
Are you sure you want to change the base?
Conversation
Ready for testing - but expect rough edges.
… in case it inspires use cases in others)
in #707 i put up some fixes but I couldn't remember the right way to try to upstream them to yours. let me know if I should fork your fork or if I could have permissions to push to that branch to collaborate
It's really promising! Thanks for all the work |
optional: z.object({ a: z.string(), b: z.number() }).optional(), | ||
// For Convex compatibility, we need to avoid patterns that produce undefined | ||
// Instead, use union with null for nullable fields and .optional() for optional fields | ||
nullableOptional: z.union([z.string(), z.null()]).optional(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't seem to be a nullable optional..
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah..this might be a hangover from before I revised the approach to optionals (overhauled it at one point during writing to recognise that objects can happily handle optionals without any special treatment)
The tests are failing but I ran it through AI and was able to fix all outstanding issues. I can commit if you like? |
@mikecann I'm happy if you're happy! Added you as collaborator too in case it makes things easier somehow. |
I'll close out #707 as I just was able to push up my changes here |
All tests pass thanks to Claude so long as the expected values in the original test have the correct assumptions
Okay I have added a commit that fixes the tests. Just to be clear the AI did all the hard work here based upon the expected values found in the failing tests. So hopefully those expected values were correct otherwise these fixes will be incorrect. I don't have enough context on Zod4 to say either way if this is correct or not but after scanning through the 3k lines of tests it all looks okay 🤷 I do like the look of the bidirectional schema that looks nice. |
Is there a package with zod v4 support on npm? The latest version of npm is 0.1.101-alpha.0 |
@hasanaktas the latest alpha now has these changes |
commit: |
Ready for testing and refinement by community - but expect rough edges!
Current version includes several opinionated decisions with a goal of writing a schema once.
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.