fix(deps): update dependency zod to v4 #901
Open
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.
This PR contains the following updates:
3.25.76->4.3.5Release Notes
colinhacks/zod (zod)
v4.3.5Compare Source
Commits:
21afffd[Docs] Update migration guide docs for deprecation of message (#5595)e36743eImprove mini treeshaking0cdc0b84.3.5v4.3.4Compare Source
Commits:
1a8bea3Add integration testse01cd02Support patternProperties for looserecord (#5592)089e5fbImprove looseRecord docsdecef9cFix lint9443aabDrop iso time in fromJSONSchema66bda74Remove .refine() from ZodMiniTypeb4ab94c4.3.4v4.3.3Compare Source
Commits:
f3b2151v4.3.3v4.3.2Compare Source
Commits:
bf96635Loosen strictObjectinside intersection (#5587)f71dc01Remove Juno (#5590)0f41e5a4.3.2v4.3.1Compare Source
Commits:
0fe8840allow non-overwriting extends with refinements. 4.3.1v4.3.0Compare Source
This is Zod's biggest release since 4.0. It addresses several of Zod's longest-standing feature requests.
z.fromJSONSchema()Convert JSON Schema to Zod (#5534, #5586)
You can now convert JSON Schema definitions directly into Zod schemas. This function supports JSON Schema
"draft-2020-12","draft-7","draft-4", and OpenAPI 3.0.The API should be considered experimental. There are no guarantees of 1:1 "round-trip soundness":
MySchema>z.toJSONSchema()>z.fromJSONSchema(). There are several features of Zod that don't exist in JSON Schema and vice versa, which makes this virtually impossible.Features supported:
string,number,integer,boolean,null,object,array)email,uri,uuid,date-time,date,time,ipv4,ipv6, and more)anyOf,oneOf,allOf)additionalProperties,patternProperties,propertyNames)prefixItems,items,minItems,maxItems)$reffor local references and circular schemasz.xor()— exclusive union (#5534)A new exclusive union type that requires exactly one option to match. Unlike
z.union()which passes if any option matches,z.xor()fails if zero or more than one option matches.When converted to JSON Schema,
z.xor()producesoneOfinstead ofanyOf.z.looseRecord()— partial record validation (#5534)A new record variant that only validates keys matching the key schema, passing through non-matching keys unchanged. This is used to represent
patternPropertiesin JSON Schema..exactOptional()— strict optional properties (#5589)A new wrapper that makes a property key-optional (can be omitted) but does not accept
undefinedas an explicit value.This makes it possible to accurately represent the full spectrum of optionality expressible using
exactOptionalPropertyTypes..apply()A utility method for applying arbitrary transformations to a schema, enabling cleaner schema composition. (#5463)
.brand()cardinalityThe
.brand()method now accepts a second argument to control whether the brand applies to input, output, or both. Closes #4764, #4836.Type predicates on
.refine()(#5575)The
.refine()method now supports type predicates to narrow the output type:ZodMapmethods:min,max,nonempty,size(#5316)ZodMapnow has parity withZodSetandZodArray:.with()alias for.check()(359c0db)A new
.with()method has been added as a more readable alias for.check(). Over time, more APIs have been added that don't qualify as "checks". The new method provides a readable alternative that doesn't muddy semantics.z.slugify()transformTransform strings into URL-friendly slugs. Works great with
.with():z.meta()andz.describe()in Zod Mini (947b4eb)Zod Mini now exports
z.meta()andz.describe()as top-level functions for adding metadata to schemas:More ergonomic intersections https://github.com/colinhacks/zod/pull/5587
When intersecting schemas that include
z.strictObject(), Zod 4 now only rejects keys that are unrecognized by both sides of the intersection. Previously, any unrecognized key from either side would cause an error.This means keys that are recognized by at least one side of the intersection will now pass validation:
When both sides are strict, only keys unrecognized by both sides will error:
New locales
am) (#5531)uz) (#5519)Bug fixes
All of these changes fix soundness issues in Zod. As with any bug fix there's some chance of breakage if you were intentionally or unintentionally relying on this unsound behavior.
.pick()and.omit()disallowed on object schemas containing refinements (#5317)Using
.pick()or.omit()on object schemas with refinements now throws an error. Previously, this would silently drop the refinements, leading to unexpected behavior.Migration: The easiest way to migrate is to create a new schema using the
shapeof the old one..extend()disallowed on object schemas with refinements (#5317)Similarly,
.extend()will throws on schemas with refinements if you are overwriting existing properties.Instead you can use
.safeExtend(), which statically ensures that you aren't changing the type signature of any pre-existing properties.Object masking methods (
.pick(),.omit()) now validate that the keys provided actually exist in the schema:Additional changes
z.iso.timewith minute precision (#5557)includesmethod params typing to acceptstring | $ZodCheckIncludesParams(#5556)implementAsyncinferred type to always be a promise (#5476)Dateinstances to numbers inminimum/maximumchecks (#5351)z.record()(#5585)~standardschema property (#5363)@__NO_SIDE_EFFECTS__for better tree-shaking (#5475)v4.2.1Compare Source
Commits:
5b5b1294.2.1v4.2.0Compare Source
Features
Implement Standard JSON Schema
https://github.com/standard-schema/standard-schema/pull/134
Implement
z.fromJSONSchema()Implement
z.xor()Implement
z.looseRecord()Commits:
af49c08Update docs for JSON Schema conversion ofz.undefined()(#5504)767f320Add.toJSONSchema()method (#5477)e17dcb6Addz.fromJSONSchema(),z.looseRecord(),z.xor()(#5534)v4.1.13Compare Source
Commits:
5c2602cUpdate AI widget (#5318)d3da530reflect the specified regex correctly in error (#5338)39f8c45faster initialization (#5352)e9e2790Clean up comment8e4739fUpdate inferred z.promise() type2849df8fix(locales): improve Dutch (nl) localization (#5367)b0d3c9fRun tests on windows6fd61b7feat unitest (#5358)a4e4bc8Lock to node 248de8badFix windows buildb2c186bUse Node LTSb73b1f6Consolidate isTransforming logicd85f3eaFix #53531bac0f3Fix test.yml86d4dadFix partial record5e6c0fdFix attw on windows27fc616Extend test timeout8d336c4Remove windows runner5be72e0chore(doc): update metadata.tsx (#5331)cb0272adocs: add 'cd zod' step to development setup instructions (#5394)24e3325docs: replace 'Refinement' with 'Transform' in transforms section (#5397)644a082chore: add resource for validating environment variables with Zod (#5403)5e1cfcfChange doc for email validation method in Zod schema (#5392)88cf944Fix: Iterate over keys in catchall object using "in" operator. (#5376)aa43732Emphasise thatenumvalidates against values, for object literal &enums (#5386)3a4bd00Improve Hebrew localization for Zod error messages (#5409)c10f9d1Fix typos (#5420)86f0ef9Documentation Improvements (#5417)e120a48Fix opt tuplef9bbb50Improve tuple0ba0f34Optimize docs caching/ISR (#5433)c3ec66cImprove docs cachingc8cce4bdocs: fix typos and links (#5428)84ec047docs(ecosystem): Add react-f3 (#5429)3396515Docs: Fix typo in safeExtend description (#5445)3d93a7dfeat: MAC address validation in v4 and mini (#5440)f2f0d17Fix dual package hazard forglobalRegistry(#5452)9fc493ffix: use oneOf for discriminated unions in JSON Schema (#5453)603dbe8Clean up regex, drop backreferencesab69b9eUpdate mac addr testsf791052chore: upgrade vitest to v4 (#5028)f97e80dfix(core): prevent infinite recursion for recursive tuples (#5089) (#5094)002e01afix(record): handle non-function constructor field in isPlainObject (#5098)6716517docs(contributing): add instructions on building @zod/docs (#5114)8b0603dFix typo in ISO time documentation (#5277)be85eccdocs(codecs): correctstringToDatesafeDecode methods (#5302)50bba54Add zodgres to ecosystem documentation (#5308)377f5d1Addzod-to-mongo-schemato ecosystem documentation (#5457)dea32d5docs(ecosystem): add fn sphere and zod-compare (#5326)02ea4c8Add Claude Code GitHub Workflow (#5460)d44253dAdd support for number literal and TypeScript's enum keys inz.record(#5334)f52344eFix vitest 40f4ce73Do not allow unsound pick/omit162fe29Add z.meta and z.describe3de39eeImplement slugify5bfc8f2Fix docs0e803a2Revert "Do not allow unsound pick/omit"a774750v4.1.132cdd82b4.1.134063e80Update check-semver scriptv4.1.12Compare Source
Commits:
0b109c3docs(ecosystem): add bupkis to the ecosystem section (#5237)d22ec0ddocs(ecosystem): add upfetch (#5238)c56a4f6docs(ecosystem): addeslint-plugin-zod-x(#5261)a0abcc0docs(metadata.mdx): fix a mistake in an example output (#5248)62bf4e4fix(ZodError): prevent flatten() from crashing on 'toString' key (#5266)02a5840refac(errors): Unify code structure and improve types (#5278)4b1922adocs(content/v4/index): fix zod version (#5289)3fcb20fAdd frrm to ecosystem (#5292)fda4c7cMake docs work without tokenaf44738Fix lint77c3c9fExport bg.ts3b94610v4.1.12v4.1.11Compare Source
Commits:
2bed4b34.1.11v4.1.10Compare Source
Commits:
7ffedd0Fix shape caching (#5263)82cd717v4.1.10v4.1.9Compare Source
Commits:
a78716dUpdate zshy (#5249)923af80Publish zod@4.1.9v4.1.8Compare Source
Commits:
36c4ee3Switch back to weakmapa1726d54.1.8v4.1.7Compare Source
Commits:
0cca351Fix variable name inconsistency in coercion documentation (#5188)aa78c27Add copy/edit buttons76452d4Update button txt937f73cFix tsconfig issue in bench976b436v4.1.6 (#5222)4309c61Fix cidrv6 validation - cidrv6 should reject invalid strings with multiple slashes (#5196)ef95a73feat(locales): Add Lithuanian (lt) locale (#5210)3803f3fdocs: update wrong contents in codeblocks inapi.mdx(#5209)8a47d5cdocs: update coerce example inapi.mdx(#5207)e87db13feat(locales): Add Georgian (ka) locale (#5203)c54b123docs: adds@traversable/zodand@traversable/zod-testto v4 ecosystem (#5194)c27a294Fix two tiny grammatical errors in the docs. (#5193)23a2d66docs: fix broken links in async refinements and transforms references (#5190)845a230fix(locales): Add type name translations to Spanish locale (#5187)27f13d6Improve regex precision and eliminate duplicates in regexes.ts (#5181)a8a52b3fix(v4): fix Khmer and Ukrainian locales (#5177)887e37cUpdate slugse1f1948fix(v4): ensure array defaults are shallow-cloned (#5173)9f65038docs(ecosystem): add DRZL; fix Prisma Zod Generator placement (#5215)aa6f0f0More fixes (#5223)aab33564.1.7v4.1.6Compare Source
v4.1.5Compare Source
Commits:
530415fUpdate docsb7b081dUpdate z.function() type to support array input (#5170)780cf574.1.5v4.1.4Compare Source
Commits:
3291c61fix(v4): toJSONSchema - wrong tuple withnulloutput when targetingopenapi-3.0(#5156)23f41c7test(v4): toJSONSchema - usevalidateOpenAPI30Schemain all relevant scenarios (#5163)0a09fd2Update installation instructions4ea5fec4.1.4v4.1.3Compare Source
Commits:
98ff675Drop stringToBooleana410616Fix typo0cf4589fix(v4): toJSONSchema - add missing oneOf inside items in tuple conversion (#5146)8bf0c16fix(v4): toJSONSchema tuple path handling for draft-7 with metadata IDs (#5152)5c5fa90fix(v4): toJSONSchema - wrong record output when targetingopenapi-3.0(#5141)87b97ccdocs(codecs): update example to use payloadSchema (#5150)309f358fix(v4): toJSONSchema - output numbers with exclusive range correctly when targetingopenapi-3.0(#5139)1e71ca9docs: fix refine fn to encode works properly (#5148)a85ec3cfix(docs): correct example to useLooseDoginstead ofDog(#5136)3e982744.1.3v4.1.2Compare Source
Commits:
e45e61bImprove codec docs25a4c37fix(v4): toJSONSchema - wrong record tuple output when targetingopenapi-3.0(#5145)0fa4f46Use method form in codecs.mdx940383dUpdate JSON codec and docs3009fa84.1.2v4.1.1Compare Source
Commits:
648eb43Remove codecs from sidebare7e39a99Improve codec docse5085beAdd images028b289Add methods10cc9944.1.1v4.1.0Compare Source
The first minor version since the introduction of Zod 4 back in May. This version contains a number of features that barely missed the cut for the 4.0 release. With Zod 4 stable and widely adopted, there's more time to resume feature development.
Codecs
This is the flagship feature of this release. Codecs are a new API & schema type that encapsulates a bi-directional transformation. It's a huge missing piece in Zod that's finally filled, and it unlocks some totally new ways to use Zod.
New top-level functions are added for processing inputs in the forward direction ("decoding") and backward direction ("encoding").
.parse()vs.decode()Both
.parse()anddecode()process data in the "forward" direction. They behave identically at runtime.There is an important difference however. While
.parse()accepts any input,.decode()expects a strongly typed input. That is, it expects an input of typestring, whereas.parse()acceptsunknown.Encoding
You can use any Zod schema with
.encode(). The vast majority of Zod schemas are non-transforming (the input and output types are identical) so.decode()and.encode()behave identically. Only certain schema types change their behavior:B->Aand executes theencodetransform during encodingB->Ainstead ofA->BThe usual async and safe variants exist as well:
Example codecs
Below are some "worked examples" for some commonly-needed codecs. These examples are all tested internally for correctness. Just copy/paste them into your project as needed. There is a more comprehensive set available at zod.dev/codecs.
stringToBigIntConverts
bigintinto a serializable form.jsonParses/stringifies JSON data.
To further validate the data,
.pipe()the result of this codec into another schema.Further reading
For more examples and a technical breakdown of how encoding works, reads theannouncement blog post and new Codecs docs page. The docs page contains implementations for several other commonly-needed codecs:
stringToNumberstringToIntstringToBigIntnumberToBigIntisoDatetimeToDateepochSecondsToDateepochMillisToDatejsonCodecutf8ToBytesbytesToUtf8base64ToBytesbase64urlToByteshexToBytesstringToURLstringToHttpURLuriComponentstringToBoolean.safeExtend()The existing way to add additional fields to an object is to use
.extend().Unfortunately this is a bit of a misnomer, as it allows you to overwrite existing fields. This means the result of
.extend()may not literallyextendthe original type (in the TypeScript sense).To enforce true
extendslogic, Zod 4.1 introduces a new.safeExtend()method. This statically enforces that the newly added properties conform to the existing ones.Importantly, this new API allows you to safely extend objects containing refinements.
Previously (in Zod 4.x) any refinements attached to the base schema were dropped in the extended result. This was too unexpected. It now throws an error. (Zod 3 did not support extension of refined objects either.)
z.hash()A new top-level string format for validating hashes produced using various common algorithms & encodings.
The following hash algorithms and encodings are supported. Each cell provides information about the expected number of characters/padding.
"hex""base64""base64url""md5""sha1""sha256""sha384""sha512"z.hex()To validate hexadecimal strings of any length.
Additional changes
FFFFFFFF-FFFF-FFFF-FFFF-FFFFFFFFFFFF) per the RFC$ZodFunctionis now a subtype of$ZodTypeCommits
edd4fea- Closes #51275d4a315- Closes #5116f3f0955- Closes #51080114d5b- #51223b077c3- #51211e06af8- #5113b01b6f3— #5052571ab0c— #5051d3ea111— #5049b8e3f87— #4865v4.0.17Compare Source
Commits:
1cebf33Add blog (#5074)fc1e556Fixes #5073cc63f95v4.0.17v4.0.16Compare Source
Commits:
d589186fix: ensure keyof returns enum (#5045)4975f3afeat: add discriminator generic (#5044)0a463e3Update speakeasy files12658afFix Edit page buttons47e6604fix:edit this pagebutton, now redirects to correct url using the new path (#5056)7207a2dUpdate Hey API link to Zod v3 plugin (#5060)6887ff3Update Hey API link to Zod plugin (#5059)ffff1aaClone POJO objects during defaulting/prefaultinga227cb3v4.0.16v4.0.15Compare Source
Commits:
7e7e346Clean up docsf2949a8[docs] Fix migration guide upgrade command (#5021)d43cf19Fix recursive object initialization errors with check() and other methods (#5018)3de2b63fix: remove redundant Required<> from input and output type definitions (#5033)93553bdAdd needs info03cfa8d4.0.15v4.0.14Compare Source
Commits:
99391a8Docs: Fix typo (#5005)e25303eDocs: fix typo (#5008)dbb05efAdd JSON Schema draft-04 output (#4811)b8257d7Improve tuple recursive inference.9bdbc2fAvoid infinite loops in defineLazy. Fixes #4994.af96ad44.0.14v4.0.13Compare Source
Commits:
362eb33](https://redirect.github.com/colinhacks/zod/commit/362eb33093e9c5f306eeec95eConfiguration
📅 Schedule: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).
🚦 Automerge: Disabled by config. Please merge this manually once you are satisfied.
♻ Rebasing: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.
🔕 Ignore: Close this PR and you won't be reminded about this update again.
This PR has been generated by Renovate Bot.