chore(deps): update dependency zod to v4.3.5
This MR contains the following updates:
| Package | Change | Age | Confidence |
|---|---|---|---|
| zod (source) | 4.1.5 → 4.3.5 |
Release Notes
colinhacks/zod (zod)
v4.3.5
Commits:
-
21afffd[Docs] Update migration guide docs for deprecation of message (#5595) -
e36743eImprove mini treeshaking -
0cdc0b84.3.5
v4.3.4
Commits:
-
1a8bea3Add integration tests -
e01cd02Support patternProperties for looserecord (#5592) -
089e5fbImprove looseRecord docs -
decef9cFix lint -
9443aabDrop iso time in fromJSONSchema -
66bda74Remove .refine() from ZodMiniType -
b4ab94c4.3.4
v4.3.3
Commits:
-
f3b2151v4.3.3
v4.3.2
Commits:
v4.3.1
Commits:
-
0fe8840allow non-overwriting extends with refinements. 4.3.1
v4.3.0
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.
import * as z from "zod";
const schema = z.fromJSONSchema({
type: "object",
properties: {
name: { type: "string", minLength: 1 },
age: { type: "integer", minimum: 0 },
},
required: ["name"],
});
schema.parse({ name: "Alice", age: 30 }); // ✅
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:
- All primitive types (
string,number,integer,boolean,null,object,array) - String formats (
email,uri,uuid,date-time,date,time,ipv4,ipv6, and more) - Composition (
anyOf,oneOf,allOf) - Object constraints (
additionalProperties,patternProperties,propertyNames) - Array constraints (
prefixItems,items,minItems,maxItems) -
$reffor local references and circular schemas - Custom metadata is preserved
z.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.
const schema = z.xor([z.string(), z.number()]);
schema.parse("hello"); // ✅
schema.parse(42); // ✅
schema.parse(true); // ❌ zero matches
When converted to JSON Schema, z.xor() produces oneOf instead of anyOf.
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 patternProperties in JSON Schema.
const schema = z.looseRecord(z.string().regex(/^S_/), z.string());
schema.parse({ S_name: "John", other: 123 });
// ✅ { S_name: "John", other: 123 }
// only S_name is validated, "other" passes through
.exactOptional() — strict optional properties (#5589)
A new wrapper that makes a property key-optional (can be omitted) but does not accept undefined as an explicit value.
const schema = z.object({
a: z.string().optional(), // accepts `undefined`
b: z.string().exactOptional(), // does not accept `undefined`
});
schema.parse({}); // ✅
schema.parse({ a: undefined }); // ✅
schema.parse({ b: undefined }); // ❌
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)
const setCommonChecks = <T extends z.ZodNumber>(schema: T) => {
return schema.min(0).max(100);
};
const schema = z.number().apply(setCommonChecks).nullable();
.brand() cardinality
The .brand() method now accepts a second argument to control whether the brand applies to input, output, or both. Closes #4764, #4836.
// output only (default)
z.string().brand<"UserId">(); // output is branded (default)
z.string().brand<"UserId", "out">(); // output is branded
z.string().brand<"UserId", "in">(); // input is branded
z.string().brand<"UserId", "inout">(); // both are branded
Type predicates on .refine() (#5575)
The .refine() method now supports type predicates to narrow the output type:
const schema = z.string().refine((s): s is "a" => s === "a");
type Input = z.input<typeof schema>; // string
type Output = z.output<typeof schema>; // "a"
ZodMap methods: min, max, nonempty, size (#5316)
ZodMap now has parity with ZodSet and ZodArray:
const schema = z.map(z.string(), z.number())
.min(1)
.max(10)
.nonempty();
schema.size; // access the size constraint
.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.string().with(
z.minLength(5),
z.toLowerCase()
);
// equivalent to:
z.string().check(
z.minLength(5),
z.trim(),
z.toLowerCase()
);
z.slugify() transform
Transform strings into URL-friendly slugs. Works great with .with():
// Zod
z.string().slugify().parse("Hello World"); // "hello-world"
// Zod Mini
// using .with() for explicit check composition
z.string().with(z.slugify()).parse("Hello World"); // "hello-world"
z.meta() and z.describe() in Zod Mini (947b4eb)
Zod Mini now exports z.meta() and z.describe() as top-level functions for adding metadata to schemas:
import * as z from "zod/mini";
// add description
const schema = z.string().with(
z.describe("A user's name"),
);
// add arbitrary metadata
const schema2 = z.number().with(
z.meta({ deprecated: true })
);
More ergonomic intersections #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:
const A = z.strictObject({ a: z.string() });
const B = z.object({ b: z.string() });
const C = z.intersection(A, B);
// Keys recognized by either side now work
C.parse({ a: "foo", b: "bar" }); // ✅ { a: "foo", b: "bar" }
// Extra keys are stripped (follows strip behavior from B)
C.parse({ a: "foo", b: "bar", c: "extra" }); // ✅ { a: "foo", b: "bar" }
When both sides are strict, only keys unrecognized by both sides will error:
const A = z.strictObject({ a: z.string() });
const B = z.strictObject({ b: z.string() });
const C = z.intersection(A, B);
// Keys recognized by either side work
C.parse({ a: "foo", b: "bar" }); // ✅
// Keys unrecognized by BOTH sides error
C.parse({ a: "foo", b: "bar", c: "extra" });
// ❌ ZodError: Unrecognized key: "c"
New locales
import * as z from "zod";
import { uz } from "zod/locales";
z.config(uz());
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.
const schema = z.object({
password: z.string(),
confirmPassword: z.string(),
}).refine(data => data.password === data.confirmPassword);
schema.pick({ password: true });
// 4.2: refinement silently dropped ⚠️
// 4.3: throws error ❌
Migration: The easiest way to migrate is to create a new schema using the shape of the old one.
const newSchema = z.object(schema.shape).pick({ ... })
⚠ ️ overwriting properties with.extend() disallowed on object schemas with refinements (#5317)
Similarly, .extend() will throws on schemas with refinements if you are overwriting existing properties.
const schema = z.object({
a: z.string()
}).refine(/* ... */);
schema.extend({ a: z.number() }); // 4.3: throws error ❌
Instead you can use .safeExtend(), which statically ensures that you aren't changing the type signature of any pre-existing properties.
const schema = z.object({
a: z.string(),
}).refine(/* ... */);
schema.safeExtend({
a: z.string().min(5).max(10)
}); // ✅ allows overwrite, preserves refinement
⚠ ️ Stricter object masking methods (#5581)
Object masking methods (.pick(), .omit()) now validate that the keys provided actually exist in the schema:
const schema = z.object({ a: z.string() });
// 4.3: throws error for unrecognized keys
schema.pick({ nonexistent: true });
// error: unrecognized key: "nonexistent"
Additional changes
- Fixed JSON Schema generation for
z.iso.timewith minute precision (#5557) - Fixed error details for tuples with extraneous elements (#5555)
- Fixed
includesmethod params typing to acceptstring | $ZodCheckIncludesParams(#5556) - Fixed numeric formats error messages to be inclusive (#5485)
- Fixed
implementAsyncinferred type to always be a promise (#5476) - Tightened E.164 regex to require a non-zero leading digit and 7–15 digits total (#5524)
- Fixed Dutch (nl) error strings (#5529)
- Convert
Dateinstances to numbers inminimum/maximumchecks (#5351) - Improved numeric keys handling in
z.record()(#5585) - Lazy initialization of
~standardschema property (#5363) - Functions marked as
@__NO_SIDE_EFFECTS__for better tree-shaking (#5475) - Improved metadata tracking across child-parent relationships (#5578)
- Improved locale translation approach (#5584)
- Dropped id uniqueness enforcement at registry level (#5574)
v4.2.1
Commits:
-
5b5b1294.2.1
v4.2.0
Features
Implement Standard JSON Schema
standard-schema/standard-schema#134
Implement z.fromJSONSchema()
const jsonSchema = {
type: "object",
properties: {
name: { type: "string" },
age: { type: "number" }
},
required: ["name"]
};
const schema = z.fromJSONSchema(jsonSchema);
Implement z.xor()
const schema = z.xor(
z.object({ type: "user", name: z.string() }),
z.object({ type: "admin", role: z.string() })
);
// Exactly one of the schemas must match
Implement z.looseRecord()
const schema = z.looseRecord(z.string(), z.number());
// Allows additional properties beyond those defined
Commits:
-
af49c08Update docs for JSON Schema conversion ofz.undefined()(#5504) -
767f320Add.toJSONSchema()method (#5477) -
e17dcb6Addz.fromJSONSchema(),z.looseRecord(),z.xor()(#5534)
v4.1.13
Commits:
-
5c2602cUpdate AI widget (#5318) -
d3da530reflect the specified regex correctly in error (#5338) -
39f8c45faster initialization (#5352) -
e9e2790Clean up comment -
8e4739fUpdate inferred z.promise() type -
2849df8fix(locales): improve Dutch (nl) localization (#5367) -
b0d3c9fRun tests on windows -
6fd61b7feat unitest (#5358) -
a4e4bc8Lock to node 24 -
8de8badFix windows build -
b2c186bUse Node LTS -
b73b1f6Consolidate isTransforming logic -
d85f3eaFix #5353 -
1bac0f3Fix test.yml -
86d4dadFix partial record -
5e6c0fdFix attw on windows -
27fc616Extend test timeout -
8d336c4Remove windows runner -
5be72e0chore(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 tuple -
f9bbb50Improve tuple -
0ba0f34Optimize docs caching/ISR (#5433) -
c3ec66cImprove docs caching -
c8cce4bdocs: 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 backreferences -
ab69b9eUpdate mac addr tests -
f791052chore: 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 4 -
0f4ce73Do not allow unsound pick/omit -
162fe29Add z.meta and z.describe -
3de39eeImplement slugify -
5bfc8f2Fix docs -
0e803a2Revert "Do not allow unsound pick/omit" -
a774750v4.1.13 -
2cdd82b4.1.13 -
4063e80Update check-semver script
v4.1.12
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 token -
af44738Fix lint -
77c3c9fExport bg.ts -
3b94610v4.1.12
v4.1.11
Commits:
-
2bed4b34.1.11
v4.1.10
Commits:
v4.1.9
Commits:
v4.1.8
Commits:
v4.1.7
Commits:
-
0cca351Fix variable name inconsistency in coercion documentation (#5188) -
aa78c27Add copy/edit buttons -
76452d4Update button txt -
937f73cFix tsconfig issue in bench -
976b436v4.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 slugs -
e1f1948fix(v4): ensure array defaults are shallow-cloned (#5173) -
9f65038docs(ecosystem): add DRZL; fix Prisma Zod Generator placement (#5215) -
aa6f0f0More fixes (#5223) -
aab33564.1.7
v4.1.6
Configuration
-
If you want to rebase/retry this MR, check this box
This MR has been generated by Renovate Bot.