v4.3.0
Breaking Changes📦 zodView on GitHub →
⚠ 2 breaking✨ 12 features🐛 2 fixes🔧 14 symbols
Summary
Zod 4.x introduces major features including JSON Schema to Zod conversion, exclusive unions (xor), exact optional properties, and improved intersection logic for strict objects.
⚠️ Breaking Changes
- Intersections involving z.strictObject() now only reject keys unrecognized by BOTH sides of the intersection, rather than either side. This changes validation behavior for strict object intersections.
- Bug fixes to .pick() and .omit() may cause breakages if code relied on previously unsound behavior (truncated in notes).
Migration Steps
- Review usage of z.intersection() with z.strictObject() as validation logic for unrecognized keys has changed.
- If using .check(), consider aliasing to .with() for better readability.
- Update locale imports if using Armenian or Uzbek translations.
✨ New Features
- z.fromJSONSchema(): Convert JSON Schema (Draft 4, 7, 2020-12, and OpenAPI 3.0) to Zod schemas.
- z.xor(): Exclusive union type requiring exactly one option to match.
- z.looseRecord(): Partial record validation that passes through non-matching keys.
- .exactOptional(): Strict optional properties that can be omitted but do not accept explicit undefined.
- .apply(): Utility method for applying arbitrary transformations to a schema.
- .brand() cardinality: Added second argument to control branding on 'in', 'out', or 'inout'.
- Type predicates on .refine(): Support for 's is T' to narrow output types.
- ZodMap methods: Added .min(), .max(), .nonempty(), and .size parity with ZodSet/ZodArray.
- .with(): Added as a more readable alias for .check().
- z.slugify(): New transform to convert strings into URL-friendly slugs.
- Zod Mini metadata: Added z.meta() and z.describe() as top-level functions.
- New locales: Added support for Armenian (am) and Uzbek (uz).
🐛 Bug Fixes
- Fixed soundness issues in .intersection() when using strict objects.
- Addressed soundness issues in .pick() and .omit() methods.
🔧 Affected Symbols
z.fromJSONSchemaz.xorz.looseRecordz.ZodObject.exactOptionalz.ZodType.applyz.ZodType.brandz.ZodType.refinez.ZodMapz.ZodType.withz.slugifyz.metaz.describez.intersectionz.strictObject