-
Notifications
You must be signed in to change notification settings - Fork 16
feat: update to zod v4 #1038
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
Merged
Merged
feat: update to zod v4 #1038
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
…chema types" This reverts commit 9c10784.
Code PushUp🤨 Code PushUp report has both improvements and regressions – compared current commit cbd31d7 with previous commit ed01057. 🕵️ See full comparison in Code PushUp portal 🔍 🏷️ Categories👍 3 groups improved, 👎 2 groups regressed, 👍 4 audits improved, 👎 6 audits regressed, 14 audits changed without impacting score🗃️ Groups
16 other groups are unchanged. 🛡️ Audits
581 other audits are unchanged. |
vmasek
approved these changes
Jul 29, 2025
Thanks for this refactor, I was looking forward to it since the Zod 4 announcement 🚀 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Updates to Zod 4. This required several changes to our Zod code (see full migration guide if interested):
z.string({ description: '...' })
orz.object(..., { description: '...' })
) are no longer supported, requires additional method call. Usedschema.describe('...')
(syntax sugar forschema.meta({ description: '...' })
, which is itself syntax sugar forz.globalRegistry.add(schema, { description: '...' })
- see metadata in Zod 4).refine
has been dropped, i.e..refine(validatorFn, messageFn)
no longer works. Seems that error messages can only be set statically via.refine
, so I refactored these validations to use the more flexible.check(ctx => ...)
method. To reduce verbosity, I've created some helper functions that serve our purposes (seechecks.ts
andchecks.unit.test.ts
).z.function
- it no longer returns a Zod schema, but a function factory. I created a helper function to convert it to a schema, and added metadata sozod2md
can recognize the function signature (seefunction.ts
andfunction.unit.test.ts
).zod-validation-error
package with newprettifyError
function provided byzod
.z.lazy
for our tree schemas. I had to keep the type annotations in the end, as inferringchildren
type only worked correctly in VSCode, buttsc
in our build inferredRecord<string, unknown>
, leading to build errors inutils
andcore
.z.record
, both key and value schemas are now required (keys were implicitlyz.string()
in v3). Also, enum keys are now exhaustive to match TypeScript behaviour, soz.partialRecord
is used where keys are supposed to be optional.Also updated
zod2md
, were I recently added support forzod@4
.zod/v4
andzod/v4-mini
matejchalk/zod2md#18A few of the Zod methods we're using are now deprecated in v4. I'll refactor those in a follow-up PR.