Compare Versions - zod
Commits:
- 9977fb0868432461de265a773319e80a90ba3e37 Add brand.dev to sponsors
- f4b7bae3468f6188b8f004e007d722148fc91d77 Update pullfrog.yml (#5634)
- 251d7163a0ac7740fee741428d913e3c55702ace Clean up workflow_call
- edd4132466da0f5065a8e051b599d01fdd1081d8 fix: add missing User-agent to robots.txt and allow all (#5646)
- 85db85e9091d0706910d60c7eb2e9c181edd87bd fix: typo in codec.test.ts file (#5628)
- cbf77bb12bdfda2e054818e79001f5cb3798ce76 Avoid non null assertion (#5638)
- dfbbf1c1ae0c224b8131d80ddf0a264262144086 Avoid re-exported star modules (#5656)
- 762e911e5773f949452fd6dd4e360f2362110e8e Generalize numeric key handling
- ca3c8629c0c2715571f70b44c2433cad3db7fe4e v4.3.6
Commits:
- 21afffdb42ccab554036312e33fed0ea3cb8f982 [Docs] Update migration guide docs for deprecation of message (#5595)
- e36743e513aadb307b29949a80d6eb0dcc8fc278 Improve mini treeshaking
- 0cdc0b8597999fd9ca99767b912c1e82c1ff2d6c 4.3.5
Commits:
- 1a8bea3b474eada6f219c163d0d3ad09fadabe72 Add integration tests
- e01cd02b2f23d7e9078d3813830b146f8a2258b4 Support patternProperties for looserecord (#5592)
- 089e5fbb0f58ce96d2c4fb34cd91724c78df4af5 Improve looseRecord docs
- decef9c418d9a598c3f1bada06891ba5d922c5cd Fix lint
- 9443aab00d44d5d5f4a7eada65fc0fc851781042 Drop iso time in fromJSONSchema
- 66bda7491a1b9eab83bdeec0c12f4efc7290bd48 Remove .refine() from ZodMiniType
- b4ab94ca608cd5b581bfc12b20dd8d95b35b3009 4.3.4
Commits:
- f3b2151959d215d405f54dff3c7ab3bf1fd887ca v4.3.3
Commits:
- bf96635d243118de6e4f260077aa137453790bf6 Loosen strictObjectinside intersection (#5587)
- f71dc0182ab0f0f9a6be6295b07faca269e10179 Remove Juno (#5590)
- 0f41e5a12a43e6913c9dcb501b2b5136ea86500d 4.3.2
Commits:
- 0fe88407a4149c907929b757dc6618d8afe998fc allow non-overwriting extends with refinements. 4.3.1
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 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:
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)
Commits:
- 5b5b129315fbc94a3b0d6244185eaeefcbe438d1 4.2.1
Features
Implement Standard JSON Schema
https://github.com/standard-schema/standard-schema/pull/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:
- af49c084f66339110d00e37ff71dc7b3b9f2b7ef Update docs for JSON Schema conversion of
z.undefined()(#5504) - 767f320318986e422f524b939f1a7174544fda2e Add
.toJSONSchema()method (#5477) - e17dcb63573397063e87d7c7fe10a5a78968181a Add
z.fromJSONSchema(),z.looseRecord(),z.xor()(#5534)
Commits:
- 5c2602ceb8be8941c64bbe5ac7d92cc174ae6f7e Update AI widget (#5318)
- d3da530deb713c853e79405adddf770e156d50ac reflect the specified regex correctly in error (#5338)
- 39f8c45b8a29de2330b485862b83cb35849f4238 faster initialization (#5352)
- e9e27905cc0f37cb079ea473af8359d5e17a57a1 Clean up comment
- 8e4739fadbd7de710eb67d34ba7e06a1029a68ab Update inferred z.promise() type
- 2849df8907b011ab056d67ae8e3d27577ac4ed3e fix(locales): improve Dutch (nl) localization (#5367)
- b0d3c9f628b60d358b66acf8f0ef7937fc9e8950 Run tests on windows
- 6fd61b71b85e4fef4c168a46c3ebcc574f26255f feat unitest (#5358)
- a4e4bc80e204577c698cf1369dd63c2b986d35f3 Lock to node 24
- 8de8bad0fa84194b81efd32474462d7a236a1ee4 Fix windows build
- b2c186bbae3a74a12acd385c1ced3ed978235cf8 Use Node LTS
- b73b1f61c798efdf497852872b4c19cd4111c1f3 Consolidate isTransforming logic
- d85f3ea4da53a1b232017dd4e4a2874eca4d8d76 Fix #5353
- 1bac0f37b529eb9a0d833a01200f5a898e8e6220 Fix test.yml
- 86d4dad5bc27b4b35df533c9170a552ad8c6c3bc Fix partial record
- 5e6c0fd7471636feffe5763c9b7637879da459fe Fix attw on windows
- 27fc616b8edb93cc27a4d25b37479d6e418bbccf Extend test timeout
- 8d336c4d15e1917d78b67b890f7182f26633b56f Remove windows runner
- 5be72e0ef4dceb1387febb7981079ecdeb5e2817 chore(doc): update metadata.tsx (#5331)
- cb0272a0ad9962df95832a78587f54afec685351 docs: add 'cd zod' step to development setup instructions (#5394)
- 24e3325dc63010e4f74e23caf91199652e8b12a9 docs: replace 'Refinement' with 'Transform' in transforms section (#5397)
- 644a08203ebb00e23484b3f9a986ae783ce26a9a chore: add resource for validating environment variables with Zod (#5403)
- 5e1cfcf578a47527044e85455e79c907fd913adc Change doc for email validation method in Zod schema (#5392)
- 88cf9441448608d9de24b47b8a4a4ba879fc2433 Fix: Iterate over keys in catchall object using "in" operator. (#5376)
- aa437325c5957c0cf57667cd7b8568603ee7ecd3 Emphasise that
enumvalidates against values, for object literal &enums (#5386) - 3a4bd00aaa16276ffeb2708cc083a633bd4dd756 Improve Hebrew localization for Zod error messages (#5409)
- c10f9d109874aeca6855383616c086b077d39f89 Fix typos (#5420)
- 86f0ef918bb24f4ab9f1ce2afc5cf2d1a4a99473 Documentation Improvements (#5417)
- e120a4877f4d8d076abf2db5c5cceab91a046be9 Fix opt tuple
- f9bbb50c48f9c07ca869d28d6a7086d7290b97a3 Improve tuple
- 0ba0f348f677688b69ed78473e022f5d225b41fc Optimize docs caching/ISR (#5433)
- c3ec66c74b3fbc2616e880a90751c2cad7270bb3 Improve docs caching
- c8cce4b607a7c0ca99cfb454571a3948ee9e85fb docs: fix typos and links (#5428)
- 84ec04708525d6e83e3408d5d3a21edde742bdc5 docs(ecosystem): Add react-f3 (#5429)
- 3396515cc6f04f5f346a1e00256ad09998dbaeb3 Docs: Fix typo in safeExtend description (#5445)
- 3d93a7d593c19dc1822bc96a7c9d47312c29995e feat: MAC address validation in v4 and mini (#5440)
- f2f0d178e1c526bc00ad0385706efad318bd44b0 Fix dual package hazard for
globalRegistry(#5452) - 9fc493f86f17a5fc550df78e7e261137885f51ea fix: use oneOf for discriminated unions in JSON Schema (#5453)
- 603dbe8dba6253c702ca8cf10b5299910dba3c88 Clean up regex, drop backreferences
- ab69b9ee813713a111b56a60c2df929eaf5ba426 Update mac addr tests
- f7910528901c05293bad275fffcb54a82e28fcc9 chore: upgrade vitest to v4 (#5028)
- f97e80da9197064937a58167619967bee4ebb638 fix(core): prevent infinite recursion for recursive tuples (#5089) (#5094)
- 002e01ad0fcc17b17683adafc80f2a86e8d355a9 fix(record): handle non-function constructor field in isPlainObject (#5098)
- 67165174eb8c7d5c6e76e760830f3109b4fdbd0e docs(contributing): add instructions on building @zod/docs (#5114)
- 8b0603dde684f1665bb2329111ed187f73ccf0ac Fix typo in ISO time documentation (#5277)
- be85ecc48a83e7f65ac0458d25f832fb4e28c9e7 docs(codecs): correct
stringToDatesafeDecode methods (#5302) - 50bba5462546401939920a6566a81c0d9c8ef7e1 Add zodgres to ecosystem documentation (#5308)
- 377f5d1eb05bfa2631ac1f020d118f5d3ca99c94 Add
zod-to-mongo-schemato ecosystem documentation (#5457) - dea32d52a5745eb6ed9aee2ecab4b01f4ccd0313 docs(ecosystem): add fn sphere and zod-compare (#5326)
- 02ea4c82ff3e71f39deaa14159f7ce486b337aa0 Add Claude Code GitHub Workflow (#5460)
- d44253d6498564ecd24a6248ddca4e9bf4e43058 Add support for number literal and TypeScript's enum keys in
z.record(#5334) - f52344e76bed0e69175ca8893c84736cf97b5d11 Fix vitest 4
- 0f4ce73ad0c5610c3c53857d05ebae619d229aa3 Do not allow unsound pick/omit
- 162fe298f0ec76d7f7883afbebdd732eb3c60773 Add z.meta and z.describe
- 3de39eea6f7ed286ae182093d0c91f3a6fdcca06 Implement slugify
- 5bfc8f269a81d9edc283e7920868161e4129fb23 Fix docs
- 0e803a29344a2f0ee637940cca96be3e6978b22e Revert "Do not allow unsound pick/omit"
- a774750d113982da28a2768b0a7c2de1f20c04e8 v4.1.13
- 2cdd82b663706fdf642d7f030841a5b278f9173c 4.1.13
- 4063e802d539d04182fc3e66a543ae6d1ba5658e Update check-semver script
Commits:
- 0b109c37c6b0b10e3901b56bcccb72e29a0b846f docs(ecosystem): add bupkis to the ecosystem section (#5237)
- d22ec0d26fab27151b0f1d1f98bffeaf8b011f57 docs(ecosystem): add upfetch (#5238)
- c56a4f6fab42c542b191228af61974b2328dc52f docs(ecosystem): add
eslint-plugin-zod-x(#5261) - a0abcc02900a4293dd4f30cd81580efcdd5230bb docs(metadata.mdx): fix a mistake in an example output (#5248)
- 62bf4e439e287e55c843245b49f8d34b1ad024ee fix(ZodError): prevent flatten() from crashing on 'toString' key (#5266)
- 02a584010ac92ac8a351632ae5aea3983a6f17d8 refac(errors): Unify code structure and improve types (#5278)
- 4b1922ad714e12dafaa83a40ec03275a39ac980c docs(content/v4/index): fix zod version (#5289)
- 3fcb20ff348e49aec70f45e0dca3de8a61450e77 Add frrm to ecosystem (#5292)
- fda4c7c2afbd7649261be1e7954f8c4d4de24a07 Make docs work without token
- af447384379faef28aa857fb53ef1da702c6d408 Fix lint
- 77c3c9f069a4cf168c0cbc58432803de887a6b1b Export bg.ts
- 3b946107b6c94b2ac8ff9fb451160c34dc4dd794 v4.1.12
Commits:
- 2bed4b39760d8e4d678203b5c8fcaf24c182fc9f 4.1.11
Commits:
- 7ffedd00169d8dc2e7cb7c6d878f29b03e05b3a3 Fix shape caching (#5263)
- 82cd717a0e7ee4e1737a783c7be278fa93fd8104 v4.1.10
Commits:
- a78716d91da7649a61016b81c27f49fd9e79a81e Update zshy (#5249)
- 923af801fde9f033cfd7e0e753b421a554fe3be8 Publish zod@4.1.9
Commits:
- 36c4ee354d0c1f47b7311e49f6dd4b7a11de04f5 Switch back to weakmap
- a1726d53172ba52ecf90999df73778cf416264fd 4.1.8
Commits:
- 0cca351c8b152d7c4113ab7c2a44675efb060677 Fix variable name inconsistency in coercion documentation (#5188)
- aa78c270f1b43f4665339f4b61e7cb88037b8c84 Add copy/edit buttons
- 76452d4119d800a722b692755c1168627bc95f0f Update button txt
- 937f73c90cac90bd3b99b12c792c289b50416510 Fix tsconfig issue in bench
- 976b43657d4aff6d47c73c1c86125623ea08752d v4.1.6 (#5222)
- 4309c61304daf40aab2124b5f513abe2b4df8637 Fix cidrv6 validation - cidrv6 should reject invalid strings with multiple slashes (#5196)
- ef95a73b6d33299743e5ff4f0645b98c1b0d6f72 feat(locales): Add Lithuanian (lt) locale (#5210)
- 3803f3f37168212f2178e8b8deceb7bad78ed904 docs: update wrong contents in codeblocks in
api.mdx(#5209) - 8a47d5c6ba8e4fe2f934a8e55d0cba4d81d821de docs: update coerce example in
api.mdx(#5207) - e87db1322f11ff6907e1789da28933d258ab75fd feat(locales): Add Georgian (ka) locale (#5203)
- c54b123e399a6ab266504eb1389c724af31d5998 docs: adds
@traversable/zodand@traversable/zod-testto v4 ecosystem (#5194) - c27a294f5b792f47b8e9dbb293a8ff8cfb287a3a Fix two tiny grammatical errors in the docs. (#5193)
- 23a2d6692398e3dd1ad1cdb0491b271a9f989380 docs: fix broken links in async refinements and transforms references (#5190)
- 845a230bb06bff679b5f00e10153f4dbbd50d2b6 fix(locales): Add type name translations to Spanish locale (#5187)
- 27f13d62b98cf5c501b828ba8837ff73cd6263d2 Improve regex precision and eliminate duplicates in regexes.ts (#5181)
- a8a52b3ba370b761be76953fa3986aa43c4172a4 fix(v4): fix Khmer and Ukrainian locales (#5177)
- 887e37cd7568219c54f9c2f71bbfe0300ce48376 Update slugs
- e1f19482bbed3fbaa563a0d8e09f1a577cc58ac7 fix(v4): ensure array defaults are shallow-cloned (#5173)
- 9f650385644ae319f806a965b83f79ebd252e497 docs(ecosystem): add DRZL; fix Prisma Zod Generator placement (#5215)
- aa6f0f02c2a92a266ff1495a8d2541ae46012fcb More fixes (#5223)
- aab33566bdb44a651cc3e27fde729285e4312419 4.1.7
Commits:
- 530415f927a8f7fa474c96b667efdad6e771ce4d Update docs
- b7b081d5cfd6fc19aeb71f9dc1b07bb333c37f9d Update z.function() type to support array input (#5170)
- 780cf57167cbf3902efab68f19fa21ca09cb9dd6 4.1.5
Commits:
- 3291c61fe4bc893901027ea5d50dfc6274e49caa fix(v4): toJSONSchema - wrong tuple with
nulloutput when targetingopenapi-3.0(#5156) - 23f41c7e0af107026bb1732af6b4c368d82be8d2 test(v4): toJSONSchema - use
validateOpenAPI30Schemain all relevant scenarios (#5163) - 0a09fd21336202e50565a3e22baaab9a7047fcc9 Update installation instructions
- 4ea5fec6988eb7260bc63e0eb8b4a6a0b238c414 4.1.4
Commits:
- 98ff675c313c15d3fa18b2bd01f844b1e817ee79 Drop stringToBoolean
- a410616b39eedf3b4654c0c791b0ab1868996bfb Fix typo
- 0cf45896edf8728b57c8e7f2b5a56536760afac1 fix(v4): toJSONSchema - add missing oneOf inside items in tuple conversion (#5146)
- 8bf0c1639f0d3700f01fa8aaee2d8fa5d0abbe10 fix(v4): toJSONSchema tuple path handling for draft-7 with metadata IDs (#5152)
- 5c5fa90e47df934acf6051a3ec30516baeef2eac fix(v4): toJSONSchema - wrong record output when targeting
openapi-3.0(#5141) - 87b97ccd556e6d8dc6b4f4455762cc7405b0abc9 docs(codecs): update example to use payloadSchema (#5150)
- 309f3584fd9a3856c3e0c813196210ba4b11d2a9 fix(v4): toJSONSchema - output numbers with exclusive range correctly when targeting
openapi-3.0(#5139) - 1e71ca99b92b94aac8ca45694f28864ae1654135 docs: fix refine fn to encode works properly (#5148)
- a85ec3c73c6a98a496f5dd3b6fb19ebe07e227f9 fix(docs): correct example to use
LooseDoginstead ofDog(#5136) - 3e982743f3abba6a421abb899670f70e49284af4 4.1.3
Commits:
- e45e61b675baf055f4a3ef2ddead21715a1e4fe3 Improve codec docs
- 25a4c376834db90d3bb3e70d4154e3eb6d4feb7a fix(v4): toJSONSchema - wrong record tuple output when targeting
openapi-3.0(#5145) - 0fa4f464e0e679d71b183e8811ef1e4f30aaa06a Use method form in codecs.mdx
- 940383d0523da41c4e2422b76455da39dddd6c4f Update JSON codec and docs
- 3009fa8aeb90e00bfc35c7124f3e6f8cad11d290 4.1.2
Commits:
- 648eb43c23e31f7d69ef09baba46aef4e9493b13 Remove codecs from sidebare
- 7e39a99a88a9b7f0c9c3d5fd40fbbab494365c9a Improve codec docs
- e5085beb2653f1d05a14c07c79b6f3707daf09f6 Add images
- 028b289a48f5589dca58b0b813a5a9f9e363a40b Add methods
- 10cc9941daeb28b6be5be7327e034c3388d8e60b 4.1.1
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.
const stringToDate = z.codec(
z.iso.datetime(), // input schema: ISO date string
z.date(), // output schema: Date object
{
decode: (isoString) => new Date(isoString),
encode: (date) => date.toISOString(),
}
);
New top-level functions are added for processing inputs in the forward direction ("decoding") and backward direction ("encoding").
stringToDate.decode("2025-08-21T20:59:45.500Z")
// => Date
stringToDate.encode(new Date())
// => "2025-08-21T20:59:45.500Z"
Note — For bundle size reasons, these new methods have not added to Zod Mini schemas. Instead, this functionality is available via equivalent top-level functions.
// equivalent at runtime z.decode(stringToDate, "2024-01-15T10:30:00.000Z"); z.encode(stringToDate, new Date());
.parse() vs .decode()
Both .parse() and decode() process data in the "forward" direction. They behave identically at runtime.
stringToDate.parse("2025-08-21T20:59:45.500Z");
stringToDate.decode("2025-08-21T20:59:45.500Z");
There is an important difference however. While .parse() accepts any input, .decode() expects a strongly typed input. That is, it expects an input of type string, whereas .parse() accepts unknown.
stringToDate.parse(Symbol('not-a-string'));
// => fails at runtime, but no TypeScript error
stringToDate.decode(Symbol("not-a-string"));
// ^ ❌ Argument of type 'symbol' is not assignable to parameter of type 'Date'. ts(2345)
This is a highly requested feature unto itself:
- #3860
- #1748
- #3978
- #1892
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:
- Codecs — runs from
B->Aand executes theencodetransform during encoding - Pipes — these execute
B->Ainstead ofA->B - Defaults and prefaults — Only applied in the forward direction
- Catch — Only applied in the forward direction
Note — To avoid increasing bundle size unnecessarily, these new methods are not available on Zod Mini schemas. For those schemas, equivalent top-level functions are provided.
The usual async and safe variants exist as well:
// decode methods
stringToDate.decode("2024-01-15T10:30:00.000Z")
await stringToDate.decodeAsync("2024-01-15T10:30:00.000Z")
stringToDate.safeDecode("2024-01-15T10:30:00.000Z")
await stringToDate.safeDecodeAsync("2024-01-15T10:30:00.000Z")
// encode methods
stringToDate.encode(new Date())
await stringToDate.encodeAsync(new Date())
stringToDate.safeEncode(new Date())
await stringToDate.safeEncodeAsync(new Date())
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.
stringToBigInt
Converts bigint into a serializable form.
const stringToBigInt = z.codec(z.string(), z.bigint(), {
decode: (str) => BigInt(str),
encode: (bigint) => bigint.toString(),
});
stringToBigInt.decode("12345"); // => 12345n
stringToBigInt.encode(12345n); // => "12345"
json
Parses/stringifies JSON data.
const jsonCodec = z.codec(z.string(), z.json(), {
decode: (jsonString, ctx) => {
try {
return JSON.parse(jsonString);
} catch (err: any) {
ctx.issues.push({
code: "invalid_format",
format: "json_string",
input: jsonString,
message: err.message,
});
return z.NEVER;
}
},
encode: (value) => JSON.stringify(value),
});
To further validate the data, .pipe() the result of this codec into another schema.
const Params = z.object({ name: z.string(), age: z.number() });
const JsonToParams = jsonCodec.pipe(Params);
JsonToParams.decode('{"name":"Alice","age":30}'); // => { name: "Alice", age: 30 }
JsonToParams.encode({ name: "Bob", age: 25 }); // => '{"name":"Bob","age":25}'
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().
const A = z.object({ a: z.string() })
const B = A.extend({ b: z.string() })
Unfortunately this is a bit of a misnomer, as it allows you to overwrite existing fields. This means the result of .extend() may not literally extend the original type (in the TypeScript sense).
const A = z.object({ a: z.string() }) // { a: string }
const B = A.extend({ a: z.number() }) // { a: number }
To enforce true extends logic, Zod 4.1 introduces a new .safeExtend() method. This statically enforces that the newly added properties conform to the existing ones.
z.object({ a: z.string() }).safeExtend({ a: z.number().min(5) }); // ✅
z.object({ a: z.string() }).safeExtend({ a: z.any() }); // ✅
z.object({ a: z.string() }).safeExtend({ a: z.number() });
// ^ ❌ ZodNumber is not assignable
Importantly, this new API allows you to safely extend objects containing refinements.
const AB = z.object({ a: z.string(), b: z.string() }).refine(val => val.a === val.b);
const ABC = AB.safeExtend({ c: z.string() });
// ABC includes the refinements defined on AB
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.
const md5Schema = z.hash("md5");
// => ZodCustomStringFormat<"md5_hex">
const sha256Base64 = z.hash("sha256", { enc: "base64" });
// => ZodCustomStringFormat<"sha256_base64">
The following hash algorithms and encodings are supported. Each cell provides information about the expected number of characters/padding.
| Algorithm / Encoding | "hex" | "base64" | "base64url" |
|---|---|---|---|
"md5" | 32 | 24 (22 + "==") | 22 |
"sha1" | 40 | 28 (27 + "=") | 27 |
"sha256" | 64 | 44 (43 + "=") | 43 |
"sha384" | 96 | 64 (no padding) | 64 |
"sha512" | 128 | 88 (86 + "==") | 86 |
z.hex()
To validate hexadecimal strings of any length.
const hexSchema = z.hex();
hexSchema.parse("123abc"); // ✅ "123abc"
hexSchema.parse("DEADBEEF"); // ✅ "DEADBEEF"
hexSchema.parse("xyz"); // ❌ ZodError
Additional changes
- z.uuid() now supports the "Max UUID" (
FFFFFFFF-FFFF-FFFF-FFFF-FFFFFFFFFFFF) per the RFC $ZodFunctionis now a subtype of$ZodType
Commits
- edd4feaa - Closes #5127
- 5d4a3159 - Closes #5116
- f3f09556 - Closes #5108
- 0114d5bd - #5122
- 3b077c3a - #5121
- 1e06af8e - #5113
- b01b6f39 — #5052
- 571ab0c3 — #5051
- d3ea1119 — #5049
- b8e3f877 — #4865
Commits:
- 1cebf336c560c87e6f806b9d02106fb623049f21 Add blog (#5074)
- fc1e556318159b4740ba3d6b37660e783d2a3cb7 Fixes #5073
- cc63f950158db212c5e9b75e7d22faca851ea624 v4.0.17
Commits:
- d589186c20c3dc112f5a5fda23cccd4d1f74420e fix: ensure keyof returns enum (#5045)
- 4975f3a0e9c9f0b241499d936a02f1998c66dc01 feat: add discriminator generic (#5044)
- 0a463e38e7f77b8036628ff911de515f9f9f6662 Update speakeasy files
- 12658aff60349a87972a782b64802ec901c5ebf2 Fix Edit page buttons
- 47e6604a3555811115d05bf41e50de54192e2e14 fix:
edit this pagebutton, now redirects to correct url using the new path (#5056) - 7207a2df38caaae910551b7ecf04941b00fc10c8 Update Hey API link to Zod v3 plugin (#5060)
- 6887ff34fb9bf5f6769152cf62ba9b69fa378aac Update Hey API link to Zod plugin (#5059)
- ffff1aac6a9a88fe6e7ad2659dbc7743275ea052 Clone POJO objects during defaulting/prefaulting
- a227cb3bd22aba48412a0129650b86277adc3545 v4.0.16
Commits:
- 7e7e3461aceecf3633e158df50d6bc852e7cdf45 Clean up docs
- f2949a81a06fe197c53e47c1fab024cebbd7f1f1 [docs] Fix migration guide upgrade command (#5021)
- d43cf19d5cafd505f2f8e76f13e18564470f0696 Fix recursive object initialization errors with check() and other methods (#5018)
- 3de2b6389a57a093f11ecf1820f31e5b4452c7e9 fix: remove redundant Required<> from input and output type definitions (#5033)
- 93553bd48aeac27fdeb7dcbee5b7e37628572aff Add needs info
- 03cfa8d9367c56d8c29870a83af10edc91eba34a 4.0.15
Commits:
- 99391a844271558e0f1736c9550375e82e630bbd Docs: Fix typo (#5005)
- e25303e98c8d13ea96c3296507c564011f403ffe Docs: fix typo (#5008)
- dbb05ef990c86ec6b1f6eac11b91ec7572e29c89 Add JSON Schema draft-04 output (#4811)
- b8257d7d1f51dd3cb4033a58271bb6ac8e3678c7 Improve tuple recursive inference.
- 9bdbc2f10d466050421a8e28c4b95a8a5776d150 Avoid infinite loops in defineLazy. Fixes #4994.
- af96ad4700879b0d6e390a0c65ded4e700049cb9 4.0.14
Commits:
- 362eb33093e9c5f306eeec95e36985a99aba8fc7 Fix optional + pipe handling. Closes #5002. v4.0.13
Commits:
- ff83fc916ec2b35c0008a48782fa14f84293149d Add eslint-plugin-import-zod (#4848)
- 7c9ce388ae39b2324c5ad05420ecf4732ebca6fe Update docs for z.property check (#4863)
- c432577ad1a7201631ae0a4d80e945fc4937bcc9 docs: add jwt schema docs (#4867)
- 35e6a6f6d64d7d5ba58c4cb8c80105759b977c9b Add llms.txt (#4915)
- 3ac7bf00d0d924d1afa1031b798bdd72b59117db Clean up Edit this Page
- 60a9372414955094b84aae2f30b491a039780b7c Implement
llms-full.txt(#5004) - 73a1970e7fd0cdcb2ffac3f6f7db85da849ee3d8 4.0.12
Commits:
- 8e6a5f8e48837fb403deb4025935e97a758ad6ca Fix “Edit on Github” link (#4997)
- 930a2f68d799889df4c1f662dfe61934db84fdd1 Fix number of errors in doc (#4993)
- c762dbb4fdb249cfddccdd69812da3f4b659df67 feat(locale): Add Yoruba (yo) locale (#4996)
- 9a34a3a60d92c44f695b08e4c665209aa7160e24 Zod 4.0.11 (#4981)
Commits:
- 291c1ca9864570e68a6c104d869de467f665da86 Add should-build script
- e32d99b54fff920c4b0b451e9099b472d20a3c4b Move should-build script
- d4faf71b8cc156a49bae23fc09c4d54b88f22bd5 Add v3 docs (#4972)
- dfae37195bed15dce84af0b17ef04cdc3704ef5e Update Jazz img on v3 docs
- d6cd30d3898aaf592c6077464c1a45fd0f6f66d3 fix #4973 (#4974)
- 18504960cdce29529e37415b87fed1732facf1ef Fix typo in
valype(#4960) - 4ec2f8776193642d91814521d8a4c22bbb766cb1 Add Zod Playground to zod 4 ecosystem (#4975)
- 2b571a21875e9e3299de261e512dad300878c3a1 Update docs z.enum with object literal example (#4967)
- 813451db7fcf64c5322835984eded9bfe95be1da v4.0.10 (#4978)
Commits:
- 4e7a3ef180f6a5525d9021638e9df20b3ca50456 v4.0.9 (#4970)
Commits:
- 3048d14bc7b803507302b8ee3cd1eeeffbd27396 Fix #4961
Commits:
- 7ab1b3cd2e272a74c0f7c5cde70ee23c2ef288d6 Do not continue parsing in ZodPipe if issues exists. Closes #4926.
- 34b400a5422bc30b48395cdd44007ff4e811fb71 4.0.7
Commits:
- a3e43911abb980f1830b68a440c231ae52eacec0 Unwiden catch input type (#4870)
- 499df780b10dfcce29afba3e811757f7eade9570 Add RFC 9562 mentions. Closes #4872
- d0493f3dceb117972464f01cb0765262a5ffed70 Doc tweak - spread vs destructuring (#4919)
- 8dad394b805fd18cee8e44a37dab983916e0d92c feat: Icelandic translation (#4920)
- 2ffdae1faafcc34639a7a846a55776c2a886a644 Bulgarian (bg) translation (#4928)
- 09731358f69bb1238f6e00e0ca82e28c095b800f docs: add valype to xToZodConverts (#4930)
- d2573409ab02e5d0c2a644315798999d619e4c89 Remove moduleResolution callout (#4932)
- 075970d2aeb50c840840cc44559b31b16d7b6504 docs: add coercion note to fix compile errors (#4940)
- b9e8a60ff44aa5fffc39617eec894117132fbbac Add
@hey-api/openapi-tsto Zod 3 ecosystem (#4949) - ad7b0ffd91da4f0466c97b7b5e6b60f376ae4f33 Add
@hey-api/openapi-tsto Zod 3 ecosystem (#4942) - 4619109e7927019837a3a13d4ab8bba5c72989de feat(locales): add Danish translations (#4953)
- cb84a5711b83d25c7dcf218c4c01097cf036c1f5 Point to zod-v3-to-v4 codemod in Zod 4 migration guide (#4954)
- 28a5091092b22146a26f8a4e7c18e2943f53a86a Update api.mdx (#4955)
- 7f3cf946ca9aa90031cb954d6f683cb09de4d894 Fix URL sup example (#4959)
- 17e7f3b4e1c2c97b3c9487c97ac6703a16ed1cfb Add
@hey-api/openapi-tsto Zod 4 ecosystem (#4950) - f75d85294df2ff4ccea056e8eeb7c14750fa929f fix: escapes decimal place in
z.literal(#4895) - 7dd7484802b1351c8b81d3d523aadd876fcdf73e v4.0.6 (#4941)
Commits:
- f91a73ec23f9ec28d908af2caa643a54088516c5 Support pipes in discriminated unions. Closes #4856 (#4861)
- 45afab0f846dffd591362b6f770017507eb185b5 4.0.5
Commits:
- 9335f0543d6359f9236e3e33b78cc5b2788dbe0f Adds
ZodFirstPartyTypeKindstub to fix module resolution failure insidezod-to-json-schema
Commits:
- 5905a8d810eff6f4677e6aa9e557f92a676805cf Improve check-versions script
- f3e749b1b057a2cf0a0bce7e07abec4e0520e0f8 Remove global File interface
- 44a936cb77961e57a0988d8a3c63d9c71fce69ac 4.0.2
- 74006edd49e3fe8d74010090462859593c2bd1e2 Fix JSR provenance
- ff4af5e889d4ad7136a9cde7202b16261db5c83c 4.0.3
- ce573e8799f86e2f68307eba95c2d40fc92617b7 Update test badge
- 9a7161a976d6349f738c00cb6d6528c0407a65e8 Fix versions
With this release, zod@4.0.0 has been published to npm. There were no code changes between 3.25.76 and 4.0.0!
Zod 4 has been stable for the past 6 weeks, but it was published inside zod@3.25.x on npm. this transitionary window gave the ecosystem time to incrementally support for Zod 4 (without dropping support for Zod 3). As there is now near-universal support for Zod 4 in the ecosystem, ths time feels right to finally put a bow on things 🎀
To upgrade to Zod 4:
npm upgrade zod@^4.0.0
If you’ve already migrated to Zod 4 using the subpaths, there are no changes required. however you can optionally simplify your imports (recommended)
// after upgrading to zod@4.0.0:
import * as z from "zod"; // Zod 4 (regular)
import * as z from "zod/mini" // Zod 4 Mini
// these still work, but are no longer needed
import * as z from "zod/v4";
import * as z from "zod/v4-mini":
// if you still need Zod 3
import * as z from "zod/v3"; // Zod 3
Library authors — if you've already implemented Zod 4 support according to the best practices outlined in the Library authors guide, bump your peer dependency to include zod@^4.0.0:
// package.json
{
"peerDependencies": {
"zod": "^3.25.0 || ^4.0.0"
}
}
There should be no other code changes necessary. No code changes were made between the latest 3.25.x release and 4.0.0. This does not require a major version bump.
Commits:
- 91c9ca6385bef38278605294498af06c89b9aa68 fix: cleanup _idmap of $ZodRegistry (#4837)
- 9cce1c5779aea32d00226a931a7f67d3e2529d58 docs: fix typo in flattenError example on error-formatting page (#4819) (#4833)
- a3560aeb6c3a8675a932601be79cfae897eec9d9 v3.25.76 (#4838)
- 50606616c0d291caf3210a7521da51271b918333 Release 3.25.76
- 7baee4e17f86f4017e09e12b0acdee36a5b1c087 Update index.mdx (#4831)
Commits:
- c5f349b6c4e76f879eba9fd350dd79950fcb02f9 Fix z.undefined() behavior in toJSONSchema
Commits:
- ae0dbe1f79b2421f6d91ec0796295763436b26e2 Partial record
- 39c5f71c92b9c4c39fc0a59b9375204fa140eaf0 3.25.74
Commits:
- 1021d3c230d41d600698a6d98b9db86c19f56904 v3.25.73 (#4822)
Commits:
- 4a4dac7cfb787162eeb79165d39bbb4830d4a6de Warn about id uniqueness check on Metadata page (#4782)
- 7a5838dc0da967e15a217bf5abdd81f725da46c4 feat(locale): Add Esperanto (eo) locale (#4743)
- 36fe14e1472f2a7cd71415841be8832fc4e9acc5 Fix optionality of schemas (#4769)
- 20c8c4b67b508d653012808f69c43c7cfe5b39e3 Fix re-export bug
- 8b0df10c8757a5fbd75bd65128ae183d764b3304 3.25.72
Commits:
- 66a0f34bfc746acddbfb68426b8b1b3f1d3d1727 Move source to
/src(#4808) - 2a15f44606fd66335c6ebc1f91d702bb6bc95693 3.25.71
Commits:
- bd81c7cfaa03f61365d1c708c7e0f1cac54ea9ca Add ecosystem listing to homepage
- 1ddb9719564e644722852193930a09d54f720443 Add Mobb to sponsors
- 30ba440859f5b9184817f578626ff85d484aec27 Clean up ecosystem.mdx
- 0ef1b85b5923a1a06a2afab47dbad249d105a997 Add
svelte-jsonschema-formto form integrations (#4784) - 14715f147363e88e73190bb6ddbdf008914f0b19 docs: fix Lambda spelling (#4804)
- f6da030188ea30defc025bbc672e5a81fbe93078 Add back src (#4806)
- 364200a67c9f74ef252dbfa65ea93aab8fb15c06 Revert "Add back src (#4806)"
- 16e1b67e15d794afbbc3208a0d1153ce9637f26a v3.25.70 (#4807)
Commits:
- f46946ca3b3e28122fcf8433af36c4827e9b2a97 Improve release workflow
- b6fe831e7a2cd5d26b45fafa7c303e980ac472b5 Do not clobber defaults in
- 7f986d021d28441acfc1fda6c25b3842fe4b26e7 Skip attw test if Zod isn't built
- 5576182a9b8bda42bf8ddb98b370b938765831b1 Add
exacttotoo_big/too_smallissue formats (#4802) - 8fd2fc3f91a061935cfb3d92d8e0684caec92634 3.25.69
Commits:
- d3e0f867d6ce8e310a1c6b546798561f0f501eaa feat: add zod-xlsx back to the ecosystem.tsx (#4718)
- 86112d96c22a555f6d0789ec5f66f639fd6883c4 chore: update lint-staged from v12 to v16 (#4703)
- 218a26784b0618b6c2dfd9eced8888d330427435 chore: remove unused octokit (#4708)
- a7cb6ed52e507a267d25e6eeca7dc1c82d7d5c06 fix(v4): add exact to length check issue (#4617)
- b888170c8c6cb45513e853810b7cba0e6295423b Close #4035
- 5879baf3c118c15ddd428bc59a00169c8d864792 Fix fmt
- bd1bddad9340c540dc699683c2ac02d568dae57b Fix build
- ddadfb8334c2da88bc3c5cada81b35971eeb816e Simplify basics, document reportInput
- d5e23683cab94dfd89be8a57193e33187a09ee2d Add
z.stringFormat()(#4737) - ee5615d76b93aac15d7428a17b834a062235f6a1 Drop example and examples entirely
- 4080fd9f210a4100746a470799b7d9fe00aedbca Add treeshaking discussion to docs
- cf6157a217347412e7784398f58dd3e35ccc5821 Docs
- 39947acd1526c0672fb075bc6cccc81813bb4074 Use import star everywhere
- 7e296aeeeba23f0b3c1b7a74103710012babdee0 WIP
- bb42be45db8f819b792639c3aa4b555844f1a05d Update treeshake target
- 0a49fa39348b7c72b19ddedc3b0f879bd395304b Improve mini docs
- 1b0a5e589afd6ac913b0eddc3aa615224a1495c2 Add dep
- 90fa0cdcb45975494a82ecfe4a71e6e9babe6bdb Switch to
zshy(#4777) - af3841bb98b2ebcaffabeb42b10f9735c39fc0a7 Rename play.ts
- cf12ccfa12890ab006dd812016163bd4f254bdd1 3.25.68
- 34ae421ca07caa3cff9788033197db2b801cbc0f Update snapshot
Commits:
- 7afe790d0f459278bc18e8197791db280cac341f Make $ZodLiteralDef generic
- 91274c3e154731205cc6958fd8c2ba5d48503db9 3.25.67
- c22944b029295cc0d33ee1b2273ea64e889528ff Fix race condition
Commits:
- 2b3e87bcdd399b8f99d53641648db5a764861e1b Update api.ts (#4724)
- 100e9aa874032b49a1091e702213a52decf07521 chore: include zod-validation-error to Ecosystem page (#4722)
- de3517eeb66fc6d901752ee78d4ec97e7f5d9bc6 fix(docs): prevent FOUC on website homepage logo (#4716)
- 222a663732f6f605fd47c9c95bcef602e3d1e188 Change ZodObject default to $strip. Set inst.shape in zod mini
- fb00618f7d2c888fc1a2e207b391619b6d04dc6b 3.25.66
Commits:
- 65309948ebcf926ee0570315b6254e06f59d01dd Clean up ecosystem
- 131fdbd4ea63abf8d4788855c106e51ef7e83077 fix(docs): Use array as argument of templateLiteral (#4701)
- ed648b132d55a12094b01e1abeae8a6d29b88364 chore: remove deprecated @types/chalk (#4685)
- 12dd4890e2310ca798dd4193f15372efc2cfd84b Add catchall to zod-mini
- fcb722ae09e6190c87f082db4be556c151dea8b7 Add uuid to changelog
- 8c74035ee6bcf27ab4b4398708b379713cc3eeee 3.25.65
Commits:
- b142ea8fbb9e41f8251a36ba687b90a316f65fa4 Fix $strip
- b6e59c37a0a463f90e91453a4d6b2b3db8cdbc53 Check for existence of Error.captureStackTrace
- 0c686afdc95a324330a60315c59189fa09d8c497 Remove type from mime issue path
- af88d743a7f6b8c1f5a2d43e3282c976833eeee7 Fix test
Commits:
- 7ed0c3694d324f5c02d5b224e7e3163d2fd84c52 Allow hours-only offsets. Normalize. (#4676)
- 112fff6b7866f909583cd6f62c43fb639420b069 Fix iso tests
- 6176dcb570186c4945223fa83bcf3221cbfa1af5 Improve ISO second handling (#4680)
- 8e20a2018df854734a09e81e3dfbe598c42911e3 Use consistent variable names for IP examples (#4679)
- 29e4973b065476b09f69e83c9e9ff4c6908c8a8c refactor: remove unnecessary assertion (#4672)
- c626fe100eb79fd95e557d8091a111306ecb6045 chore: update husky from v7 to v9 (#4682)
- f350a693aec24a5b70a37992df3b9e7ea36525b2 3.25.63
Commits:
- c568dea33ac42382070580687410ee47e83609c4 Drop | undefined from json schema types
- 1614fd891b40cc9d23b249abad528e38ca718065 3.25.62
Commits:
- 1c2ad877120566adc9db3a8d99c1a575bc58d216 Loose signature for index signature shapes
- afa7e672f4be0fc37ec9d35d281221ceb153baba 3.25.61
- 82b43fa9ff832b80e249b944fefb8177827136e6 Fix test
- no changes
Commits:
- aec5c4ad036cb7a2ccbda744486f48c4047316dd Fix formatting
- d3389cbfa1888ac45634a185d4aaa2df7de0aef5 refactor: change if in else to else if (#4664)
- ffc41bd9f9e5f33627112baf19247bb95d83dd13 Improve JSON Schema typing
Commits:
- 21ee3f6fceb504069ef91899248239c59e2189b9 Add Zod Sockets to Ecosystem (#4655)
- 6707ebb14c885b1c577ce64a240475e26e3ff182 v4: Preserve function types in
.meta()(#4636) - 3cecd986a4092de509bde195c7021b8871d28ea0 Added Superforms for SvelteKit (#4635)
- 305399f878450cf3f0a2b05975b58774d5226244 Fix adjectives in Japanese (#4648)
- 04dc83ea8a4e63abf424090efb23d3bc9f31a3ad feat(locale): Add Pashto (ps) locale support (#4594)
- ed933d9142318177977771c8b17b2efb49b8e53d refactor: remove unused import & imported multiple times (#4588)
- 0d87aa4ab937bb44de3400322a3dd7f95d37f862 Make id lazy
- f98ed6d55dc5f5625a6fe973e20ba6e764c22001 npmrc
- 72623011510be94e37fdc669e1bdecc983987edb remove external
- 2904af29851610e2344bfde55e6129c1b2388dda 3.25.58
Commits:
- daae643da3fe082783803d198e89877ac0f6c5f6 docs: fix broken link in Zod Core errors docs (#4640)
- e57ddcab25f97acff7ac5663502daf9455671356 Replace non existing error instance. (#4649)
- 20b464d6429d35b2ef5416c3c3cfefeb1c0eb50e Add tests, use ReadonlyArray
- 9548f1198b0bcbd8b69034fee2dd22030878f7d8 chore: allow readonly arrays in
z.literal(#4643) - 303f1e9612e896ba9fe1ef5059da659b54f119e6 fix: issc type at ZodCheckLessThan (#4659)
- fa83a8a26c394c40a5359f50c850089e29412107 Fix pluto
- 32ae1cd86c1b05de1212f2977d6ce898847d67da Improve stringbool (#4661)
- 76ddfe3d7e45864169c5331d32413b699fd0cdec 3.25.57
Commits:
- 64bfb7001cf6f2575bf38b5e6130bc73b4b0e371 3.25.56
Commits:
- 44141ea1dbd48403f14704386119884aeda5cb27 3.25.55
Commits:
- 8ab237423cd8fdca58dc9e18f45d48d56ca2a24d fix(util): cross realm IsPlainObject check (#4627)
- 2be1c6ad909a9d0598d9f45fedc9038213130529 Fix generic assignability issue. 3.25.54
Commits:
- a6adb148012f59d734245c637a577ed413a484e7 zod mini internals (#4631)
- da4f92170ac838029178c4622015dbdae4a1de7c 3.25.53
Commits:
- 2954f40a4e41f61e835ba211ff084467dca1f41e Fix json (#4630)
- 51dc6f9361851e64a925c3f4ee9364ce4da4c4e7 3.25.52
- e479ea76ae1571064c3dade621b3af0ea2dff942 Add test cast for deferred self-recursion
Commits:
- d7ffdfa73a800ea810218431d1dd751f15d0fba4 Remove _
- 50ef910565a14c127942442b7e09596afcfdca5f Add output type generic test
- eb14475c3ca14562c4bf11c2111a1fbfa3d114b6 Improve docs
- 32104c2801f01edac3fb3168017b09b6c43f3cef Improve extend docs
- f67332f9fbcae13ce59dbb1eeb67f9c4c60bdcd9 Docs
- 8230237b3453b02bf34b81d0bc11b40d9868cd09 Standardize string format continuability
- c58bd9b0125881caee03a408eae88ec1dc5eb18b 3.25.51
Commits:
- 5fdece94bf1ada76e5742f2755d45d3711a8e962 fix(v4): reflect inclusive boundaries in minLength/maxLength issue objects (#4591)
- 4897269451f0b0afeb2313389d20ffa1f22ce8b1 Restructure: mitigate excessively deep errors (#4599)
- a88a080f0b9782a87b5732cb9cd96fc2b1a71794 Improve prototype tests
- c7833356a3211d32ae322739a7a6f66dce52ed5f 3.25.50
Commits:
- 74458e9ccec6d0d4a7af02f66e463a07ee5cad91 docs: updated name and link of
reglelibrary (#4601) - 5cc04f3685903c0e66a65b91f758115cfcead83d docs: fix some typos on the "Defining schemas" page (#4595)
- 9a81173ba28d70d856d8db2e5fe6daedc9241fa4 Add includes position regex (#4602)
- fa7bee41ae5330aeb90b70a2b5aab228b2faa8ae fix(docs): remove z.literal(Symbol) (#4587)
- df73cb08bc3362cd298be0873cec7c42310a89a1 Make z.custom issues fatal
- 78e0eae30181cd75c987bcee98cceaf51dc62979 fix: add type to literal enum (#4590)
- a73a3b3009735c6f82531393e65a82cad6b62e05 3.25.49
Commits:
- a1276395e53df7a77219ac1a59f20e3f9c710f67 rm
console.dirfrom$ZodDiscriminatedUnion(#4593) - 343bd590278c68f86208395ab5da6c213ccc88f3 3.25.48
Commits:
- 98cd8b33e0e1b85dfe26227a05e77bbf5fc3f014 Fix more excessively deep
- 7bfc8af0f805453ac06d0d11bce7e76b01fd3240 3.25.47
Commits:
- 52808166ec4ee89ed04d0da6b86c42134f6b07e4 Improve disc union error messaging
- 4a3baf76f30048a89719018f4c5134f252debf94 Fix lint
- aff9561126e591cd9e05beda2d1c69d302bce79e Fix branded types in record
- 50e9afb5606018ecacd6c64aee90f4f8006d851b 3.25.46
Commits:
- dc2c0b0fccd893a08306ccadc8baa821b1b06a5b minor grammar typo fix (#4584)
- 6fd3b39ab65970ec7f708e0aa4d0c9e20d9d2050 fix(JSONSchema): add type for enum (#4577)
- 6be478b98c6a36895e28ab0d8b214880dc645d88 Fix ZodType assignability issues
- 69ccb67f6d9d264dd26b6ba0bcc6f2ddc90a8fbc 3.25.45
Commits:
- 91267823162009488fff03f2a7240b89767e4d7d Update input<> and output<> to prevent excessively deep in more cases
- e2d72afba3378ab81c691bc81c7e96d6f4845e06 Loosen and expand metadata typing (#4586)
- fc69453e625a1b1c1a4523def3e4e60e5f2af8ca 3.25.44
Commits:
- 508e3065ca2debf43a2a8c27845ab7c7d4fe3bb0 Fix type inference in ZodMiniType check method (#4568)
- f8fef45cfa813412beecadfbbe9d6df09ac33a86 Ecosystem: Add Express Zod API (#4579)
- 289cba3b95e522b9c66611b94c218bcdfe8566b2 Fix type inference in ZodMiniType check method (#4568)
- 011623a7daaa4e5215178073e3a0aeb2e760b2a9 Fix dts files
Commits:
- 670a6d2f6f4b5ed902fbac7e627e71eb529d834c Improve Next.js tree shaking (#4569)
- 548e7ef10912c84aa67a98da52b17dd0bffe1d9c 3.25.42
Commits:
- b898f99b070b6e03ed14c4e1f82985a36315cbc5 Update nullability section
- df1e60e381dfd8aa23fddb4a047a899ae79ca76c Fix portability issue
- 22ab436bc214d86d740e78f33ae6834d28ddc152 3.25.41
Commits:
- f97733fff4d627b7b9c85d4a4a2f758727de00cf Flatten simple intersections
- ad2fc5ee221bc5fbfad1b7695c71a8a2c9c57314 Implement OpenAPI-friendly JSON Schema for File schemas (#4567)
- d9add61a91d8035c3bf3335f2aaadb723f3a5336 Improve z.file JSON Schema, update docs with additional properties
Commits:
- d17b3091cdb00ec5113807f318de4d63fef57d69 Support array fn inputs
- f23d73c07192e4ed66c2a09954bd86af42870eaf 3.25.39
Commits:
- 11477ae593b0a01ab7e701f39d69ce170936a216 Add test
- 1574d2eed0c4ffed3ebf83492f4587a0942945d2 3.25.38
Commits:
- abc13de01b157fb67d8da54477699da44b7bcd6a Add major version section
- d6cc9993dc67cbf88aebffc2132bab5fd6a2e991 Improve inference in z.function implement
- c00ca4284f9c588ea978816e49674e0264576f9b 3.25.37
Commits:
- c5d9e7ce3b2190ea8776a75dad35c445b99cf3b1 Allow arbitary strings for JWT alg
- 99e232927bc40ce278052434170089545288131a 3.25.36
Commits:
- 5e31fd09c8131709288d4c980d45a92483a4b6e7 Update readme
- fe75806cbb64683f237ed0e4ee93b67a2c5e976d Improve discriminated union implementation (#4556)
- caee693225f51b3b895edc679a186901aefa6683 Tweak readme
- 02f2389feeba7f3ab6715b11123865be5a508677 Fix lint
- 056e3f81f5b2829ad9b3d0c47fa20f2af2e05029 Improve homepage
- 33495d51f2c5ca48311e68fd25db331b81e7cf75 Fix isPlainObject
- 3a424694a049014e13e735c97babb4bc2cca49d1 Remove defaults from JSON Schema for transforming schemas (#4557)
- edc347785d87ae24c2c48e4cf3383fc8bb995cba 3.25.35
Commits:
- e8a84912926a497e0b95fbc7aef3697314a89ce6 docs: fix mini-v4 docs related to min/max validation (#4547)
- fdb63da8cea1ecc9b055e18d3c067bcef858ee03 chore: fix typos (#4543)
- 2437ec0af3e15af293ccfd90c432878cb70dc5c6 fix: basics.mdx typo (#4542)
- 103f69becde4ae535b0e93449c07d74a24066eac Use output type for preprocess (#4552)
- 3a8edd7470a550b55aeefa365c6d3ebbd6583910 Revert "Use output type for preprocess (#4552)"
- 5bdeee4fee037f62f6b5f0d7f8b8f97ea2c17bed Abort further processing when transform is skipped (#4554)
- 182dc4907b038d188be9d6c0f6d0f3ebce0f3cb8 Abort further processing when transform is skipped (#4555)
- 7f5a76f0025d00cbfaf51ffc720be5539e0b90ec Use output type for preprocess (#4553)
- 78f285ba83adab260b8cccc51a7a932c05c10a5d Remove usage of private fields in Zod 3
- b4b3d6cb0a7dcb1ec980fedeb5bea8177f6e17ed Symlink README
- 1a977573351797008422ffff7f4c935cd6c71383 3.25.34
- 6cfead2a7ade64b09ec28921208b971c8dade6c1 Move symlink to outer
- 151242a42ce4f295a048b6fb047a2ed40bd16488 Update readme
Commits:
- 80cfd3a14cb53471783c75f9e4b341ed7e569f0f Improve runtime error for non-schema values in shape
- 741be37ef5e3c19410741efc50f183ee4d8b34b9 chore: fix comment for packages/docs/content/v4/index.mdx (#4533)
- 74662e367cfda8267bd4053b7e9b3def5718986f chore: Update README to specify TypeScript syntax highlighting for schema example (#4443)
- 3c5ffd24887e7ae2ffa9fb9fe12cd661cc40d873 Add Khmer locale support to Zod and update documentation (#4447)
- 8e827b1517c6ba224bc63fed057d61959b91ddb8 docs: Add conform to the ecosystem page (#4415)
- 7918973408e85767143a779c26044108f776350f add Swedish locale (#4451)
- 33d3bb9bd73c7f5ce7336af72a290548ff9a9d59 Fix issue #4454: Updating the contribution.md file (#4455)
- 4d8cb5d733b957a56546c8d2406cfdbc64aa691c Update bronze.tsx (#4472)
- bc15379d0c92b9c6df94e4cbf1e5e45674e20b45 Fix typo in changelog (#4496)
- 010bbe419f99da2da4c8a638d4c6f4b61fb44bcf type in error-customization.mdx (#4514)
- f3b4630141c2eda74bf8f5852f44a8933fa66027 Add inheritance diagram to docs
- b97e218c4dd3a0923db0a50f5161f3c89b5c0f8d fix: Add check for requiredKeys before assigning to json.required (#4525)
- b650a488b9ae2efd56a674ead5f837d800ee20fd nit (#4520)
- 56ae81b25ab5fd2082f7393362adaffc5d9fca9f fix v4 docs typo (#4414)
- efbcd7a866241d5e7f179aac8bf1a44e801e77ca feat(locales): add nl (#4425)
- 1ba8ddc8a866e07822b2c3693f5cb591ebac0c5d Standardize casing for locales
- 5cb48f7a642572aa0e94a1bb634f098d0d2d759a 3.25.33
- 345864f7023ae03548009bf7fa83cb1916947c95 Improve library docs
- 9379c0ce2e92172e2be94660bf58cdac031f4ea6 Improve stringbool docs
- 0828c93422d13a0692cc10813428d6e65bdebd08 Fix CI
- d1e0876a9752862c7f2d0538a161836de6f65817 Rename
- 494b944bfabd83714beb06794c06ad94b96c5876 Undo rename
- 4e44e615526fcf83904dbac0f69136bd2b622ba3 Add zh-TW
- 5a6d9866022857d17b9481b03b0ac329677fbded docs: fix typos in "Per-parse error customization" (#4549)
Commits:
- 57a1adf92650e8e3e8d9777183888217e12d6698 Fix default & prefault object handling (#4539)
- 5728656a6be643937f904f92887ecf2d22a8327f Remove PR template
- 2228c48f4a1e31cfa9fd4f6064471e151b256204 3.25.32
- 99f64fe5cec9504912a88f86361194766a83d0f9 v4(toJSONSchema): Add multiple string pattern support (#4511)
- 00275810b14f48d0b66290e45bd8606223dd3f81 Tweak patterns JSON Schema
- 564bf686001e5b432e906940698a166a4337a7c4 Update tests
- 39d84d03563d350b42ec56ffed715b805dfa6676 3.25.33
- 6b13cc94de322cead1754687469d47c5a88da68c Polish JSON Schema for patterns
- 1fa86899dc680244f73088f90de4914de384f7ae Move to top
- a19cf5597199d4353e1fdc954df8dbb8782f82a4 Update tests
- d9e315bd8ff9ffd0f1e61076443dd3ea85e46954 Unify canary and regular releasing
- d78c128b7aedb01a6e028f4dfbc46b3572c867aa v3.25.32
Commits:
- f4ae14b871a400b5529052b334ec1bd9c22d3a36 Improve util.isObject
- e656947f99e39746a50b2d4152cd07accd75d49c v3.25.31
- 7ca67d312708964069bb7178e4938e6d9bda27fb Support stringbool custom messages
Commits:
- 269e018881de390830a9863d462c371f2ba831f3 Add v4/mini path, update url docs
- 7080d97997f91fcb7cde7ee91bd61563cd09c805 Improve web url docs
- 94003c4eb05b56cbb1f691cc5e65a9cb231fb39b Improve web url docs
- 4a2e2140b3e0b72c54abceea1623ac35fa7e3909 Fix z.instanceof typing
- 3503f1b5286bc3226eef28cd23539256d9ac82f4 3.25.30
Commits:
- 592de8de6e9c1f1d41aaa68e2c8ba57adced6507 fix: Rollup comment warning. (#4462)
- f98d1a30b403a3d3e4c2f7929dfc87b528f32d88 Standardize URL behavior, clarify docs
- 6bcc9237742323a0dfa25edc16b30743e3d31b6e Fix endswith/startswith params
- 028ca36a0b084a032ae65e97d602e6aa5f87d65d Add unwrap to ZodArray
- 703aecd3fbdb47874c4fd386ebd15b8fff6fbe03 Remove interface from type enum
- 70476635f51caa89a13785c4496d6b354f61ba2e 3.25.29
- 2f77d56d4f41319eab5d1a9c143aeee93106eaf0 Fix tests
Commits:
- e012bd248d45d3204fb9554f99e8222426e29da6 Improve override docs
- 7bd15ed2b08956ba3c25704bd85a1e8e39eadf55 fix: add missing re-exports files and add new entries the published files (#4500)
- b588d2c004fb414fe0215fc4f5f41bdaace88c05 Improve z.function typing. Add .def
- 5ac95df45b5ed1c49d32bbe2e7b4de7ec33a0664 3.25.28
- 7aecb617e02ba6b40e93a1c0badde350f419f372 Clean up ZodFunction
- ed48cbbe5aa7951b52ff96dfbe3fe3d3d98d0768 bugfix: Small typo in V4 docs (#4435)
- 5e4ff20b501b3977012a0b7619f0d94b6db67e2e fix: JSON Schema > override section typo (#4428)
Commits:
- 27ccaf1d36eb826dab1cb84f7ce4e1a0782121af 3.25.27. Use for override. Add .value to ZodLiteral.
Commits:
- d0627208f847087dfb89dd142ee4ebd4b8f1a908 Fix on .register methods
- d93271e86fb09243507231a07e300acaebd0c297 Replace z.min/z.max in mini docs
Commits:
- 605286346e151f75f5a27d12f435cfb465f7f1cb Add error serialization test
- fbf88f2dd75cba4d1dc4bc8f04f2c5763d1aaf0c Document parsing with Zod Core
- 6413fa90e4aa3f113b280de8b417fa6c6bf01439 Add additionalProperties:false by default for objects in io:output mode
- 5477ea2068879e1e408fe126bb7cb819471473d9 3.25.25
Commits:
- e0fe7ae92876414946456890fed2f85802cadfd0 Fix lint
- 1780c67e9cfeb1c94ef4e18fc8e93f22a3e114c0 fix: rewrite $constructor to be compatible with Hermes (#4482)
- 053debab86b4a4531ad356d749b395b283fd7501 feat: add export entries for bundlers that don't support exports field (#4489)
- 29aba82eb2131e979723cecc49d4cfa901386fd6 Fix typos (#4495)
- ce61025516d8976bef6a091a0becbe8ad1c9a0d0 Simplify fix
- 93f296dff344afcc6bdf61279b946a0ce2695f65 Fix error name issue
Commits:
- 2529f82726955ac204add9278f609c5ccc896233 fix: update correct JSON Schema identifiers (#4485)
- 596a429e55795ed1529cb154efcd8136c04f5036 3.25.23
Commits:
- 61adf85cba3a035c005e8de173a3dc08076e4ab8 Update basics.mdx: Fix #4479 (#4480)
- f3a5fe6eeea5c86e43a23bcf1666b48dfddc6b9e Fix incorrect code block in zod safeParse documentation (#4467)
- 2a6fe867dec59fc7681289099b1c246f579b590f Update README.md (#4465)
- 8acf0e1f8ab2eaff1affe4e798468883abeae823 docs: fix safeParse sentence (#4450)
- 98c849de3b07ff335a1c8ce59f0beed9596c2211 3.25.22. Remove src and test from package. Add semver precommit check. Update release-canary
Commits:
- a2c98924956f5601358577285e7b45675e26f26f Clean up play.ts
- 6d47791be6088907af7f8e0ae3bf154164650509 Fix v.custom input type, add z.core., error map docs
Commits:
- 709dfe3d130ef696d3565f877326230a22b3e887 Add global File fallback
Commits:
- 17ee03e85495c111354cd75e50b8d239b0d92c79 v3.25.18
Commits:
- 4bf6b20cc365feb8d26f20cf91fc3076cc13d3ef Update locale docs with extension
- 7191b3cec647985f74ec96e65a2f8a9c230354de Impl tshy-style build
- c623370ff18475088f67148382d5e62c4dc80429 dist/types as commonjs
- 31e02696ac2b6d1d27eeabb92e8f909dd7ffea50 Fix locale wildcard
- 4eccc3bcd02478bbe4cde516ca347d1df435d260 3.25.17
Commits:
- 3dec3fc6313863fa6a907f78c1d5fb9526fb7dbe Fix wildcard
Commits:
- 9622b925c382a61a40931700511af1cd79f4bf65 3.25.15
- 7f4a70751daf3eb66ffed58ec2f6ae6b7214bc1a 3.25.15
Commits:
- b4f3811348ce861f1e247bf9b1e8ab8fcf22465e Fix build
- 7d613b4b7d3b98468eae71168165d54c82f07009 Add canary releasing
- 30d841d56380df7efff46f9335857051e6cbfc44 Fix build.mts
- 63f09aa14b030ceadccc009e75156d8ca7bf21e5 Fix release.yml
- 91488256192e30cd78395ceea2183f81281ce452 Update release.yml
- 65c5bdfc7f1ee318a04f243e81dab1d149cc27c4 Release canary
- c7316651c225b6b323a0eb9f79ddaa48e6ce2dca Fix CI
- fe0a527654fe1e99a5e1119cba60c66ab1b949dd v3.25.14
- ed5acb5183df6b1ba154ce6eaf4ff2a27d8ba1d6 Fix esm
Commits:
- c2cec4e3cf293bd8e6a47a90d4d9c7cb2ea1f65a v3.25.13
Commits:
- 14921aadd4b0eee6a659151bb01cdb467a16c98e Revert "Revert "Fix module resolution issue""
Commits:
- 3f9f65997fb25aff99d39fd4c27d5f14e6427af3 Revert "Fix module resolution issue"
- cb50ed609455e9817c5b57380fd1454a35adca3b 3.25.11
Commits:
- c172c199ccd0f86b539d1ba7c22db8415f7f06f3 Fix module resolution issue
Commits:
- 85928549a7c2aff851d8625588ed7aa2e394831f Zod 4 (#4074)
- 6c8bbb4c9f51a39c43e5f96be7412c46fc0e5b71 v3.25.0
- c474b37e2db06eb09244a41d329af02e3c315141 v3.25.0
- 9102fa54b0785f585a1ab68d1fbb5b3db410b2bc v3.25.0
- 46dca65d7645de5b8fdd7c0e7422d91dc7b3ef41 v3.25.1
- 2381dafe7bb47a0354881567c8d8fbeb493e031f Update Jazz
- e7f75d69389fa308ea49177dc53a4913fefe75d3 v3.25.3
- 3c7e6f56d287d9545573dcb3879f46754f968517 Fix link
- 24a5e4f329378ebd035a19a678e7b24e52036829 v3.25.4. Fix T_1 bug.
- 538efea33eddc9e4a7b7aa3e0e7c3c839da271a9 Fix copy/paste typo (#4420)
- 1c420580040edff48eb6bed1f62597d9c85516c9 Revert
Errorinheritance changes (#4424) - 6dbbecd1c05ae52c977f332cca9bd49d36f72f22 3.25.5
- d9f76e1122e08f1675c33f2794cc25e806c3f0f8 Fix shadowed generic
- a18fc02a5a47af4305c7eb3f263d02c50a1559a9 v3.25.6
- 1ea1c77391a8eafe89112094276bae1d1ce162d9 fix: iso timezone docs typo (#4423)
- d40b29520076107af4996434a3dca74f3caea256 Add
zockerto v4 Ecosystem Page (#4419) - 13226e033722dcb41dc9dbbf5fd03ab7ecca5042 Fix types issue
- 868acc16177b6885271eb537b22b20aeb221b75f 3.25.7
- 8739138b5fe8f24871007123553fc7b368dde68e Add link to writeup
- 8cf6bfc060d83cc29ac44935b4ac35ca6764a35c Add link to writeup
- d0318272b752bd336585a07b3f1273420f3576b1 Clarify versioning
- 66ee76c5d631e4215476c44300c518eea2829bc1 Typos
- 4059474389df7c8a0f03659954d78bcc0fdb4d2e Revert type fix
- e9a0798c9f08bfd6d54397b42645e9434bc395e8 Revert "Revert type fix"
- fe105a94364baa0dbb13ca83523c4514b75e7b58 v3.25.9
Commits:
- a429256d5999be4686b0da55347cc4ea65d0c5d3 Allow HH:MM format in
z.string().datetime()andz.string().time()(#4315)
Main feature: massive tsc performance improvement in .extend() courtesy of @Andarist: #4150
Commits:
- de1f090c98b40884aafc4f324010ab484da2be1e Switch to featured sponsors (#4001)
- eea05ae3dab628e7a834397414e5145e935e418b Fix headers (#4003)
- 446644f1095667f9bd6c1704ddbd35854d5ef132 Tweak feature layout (#4008)
- 1d6e1cb842ece3b2d4d583da126bc22f26367623 docs(README): add GQLoom to tools and integrations section (#3995)
- e2b9a5f9ac67d13ada61cd8e4b1385eb850c7592 Update feature (#4009)
- 0b5d29e5d9524ab9d5f08c12651a3385462298d1 Feature Mintlify (#4014)
- 47dbb2dbf3e611db08e84d6c13f66f19427c8172 Update mintlify feature (#4015)
- 69d8436f36db10d256c01da333754ea1e33d1708 Add Clerk fellowship mention (#4020)
- 850871defc2c98928f1c7e8e05e93d4a84ed3c5f Fix table format
- f204123863a3524a5659ec696ffd38952e20e4ac WIP (#4028)
- 5041dfa3521ec98066e60f97681adf9604b66e52 WIP (#4045)
- cb2b8577665d7ce2214d20b10b49c4be7deef7a0 docs: add TanStack Form to Ecosystem/Form integrations (#4055)
- 099fe85fbb5b6f8434f22ee3dbfc8a6d26b54019 docs: add oRPC to Ecosystem (#4042)
- b999b4bf340480d64bc7fef1ca5ab56b29430eca docs: Remove outdated doc 'avoid coercions that throw uncaught errors' (#4005)
- 19c6d2e2c497b2d2498cc3f9db142965617e7c2c docs: update README_KO (#4025)
- 1061293a18c8a698b082c8a4e2a65ebd3333d543 WIP (#4060)
- 07ff0da057f4df2aab299a454735d8398b4c0b54 Update link
- 4c7d8e503a324e7a9873d4c17af2a19738c63364 Update Fern art/link (#4062)
- 91dcd30ff85f92bc2140c26d7b1294e394ff0ea4 removed unnecessary console logs (#4059)
- 859ad2495e3d24559d3c8e33a00cf56e2dbaa16a Update alt tag for Retool and Stainless URL (#4071)
- 220aeda3b63460ab02b2187e460665a4bcb2572e Fix images
- b865062bf3fe086a26a8b8a52116653f570eb9bc update readme.md with zod-csv library (#4021)
- 0615af80451fe42da3c04c76b5c4b2b4a5260267 Fix formatting
- 12e58668345116601453392e2c8237acde7a5b39 Add zod 4 beta anno (#4081)
- faac697f27ba56023d5384564fc594f98c589915 Fix CI
- 8cca93b7cc3f8c5fa17303bbb82d5c531ec24f33 Fix CI
- d114394027b76c56e389d00292f5f92f137e5553 Added FullProduct.dev to 'Powered by Zod' in Ecosystem section (#4131)
- a801ddd380196778e45a59920f167bfab8f32106 Fix broken logo link (#3974)
- 8fc309a8000493a86d60a8a31cb9d73850f427dc Add packages/docs
- bfd0913f08d77b0e6d1633bc0f21b56712e37720 Remove packages/docs
- 3e602d43124220ae0001ae761f76ff117cc2f741 Optimize
extendShape(#4150) - 06db7f855f49f75acc7d53ec0d7c4cd3b4dcaa17 3.24.3
- a18d25b297d1a47dca8f1701afb18079c05e1e4c add back packages/docs
Notes
Support asynchronous checks in z.custom() .
const customSchema = z.custom<number>(async (x) => {
return typeof x === "number";
});
Commits:
- cdcf9d4263cc544c7cb49855b31612d4305da72c Bump rollup from 2.79.1 to 2.79.2 (#3895)
- a2ad37099e8f7117d231cc2c72d0e471893643b2 Bump find-my-way from 8.2.0 to 8.2.2 (#3897)
- 0e02d66d1bcaad9c0f92609431e1726e088a8112 Bump nanoid from 3.3.7 to 3.3.8 (#3896)
- 96be65f0d71b0bf8e8f330dc0541cc895edd6459 Bump cross-spawn from 7.0.3 to 7.0.6 (#3882)
- f7ad26147ba291cb3fb257545972a8e00e767470 Bump micromatch from 4.0.7 to 4.0.8 (#3748)
- d724620c341e1801db9513f681f731afb3df452a Add
zod-structto utilities for Zod (#3921) - 6b96cfd4307649df6a451d74e06c47ac88c01dfe Update README.md (#3949)
- e376cda8e14d3caa09bc2148ffc668748118db6b Add Courier to README (#3961)
- 8a099deaef71b3d8bd65986a745b88f08cb28ba5 Add CodeRabbit to sponsors (#3975)
- 587d160badbe96d1adec1e8ff9d93bbcb3f91c4f WIP (#3976)
- 9d3af2ee5263971bc0dd7e4927cd07ee854fe4db Add CodeRabbit at Platinum (#3981)
- eedeb4b69f9f4bb58401d9cb27c8038a042f2c7f docs(X to Zod): Update url for runtyping (#3971)
- 706f49f9fb852cdde667b65ccb9b765444a86de7 fix: redirect url to correct url (#3939)
- 7365b7d5564793c42ee02815880463b8bee30028 docs: translate README to Korean (#3934)
- b7e173de06e223a7a6510903a4110634e2fb5d92 Format
- 1dd44a0d6f8073f7c417e09ec96580b9ae9bda23 Support async z.custom
- e30870369d5b8f31ff4d0130d4439fd997deb523 v3.24.2
Commits:
- 0c6cbbdd1315683dd3d589fbdc5765c26431dcc9 Undeprecate .nonempty()
- 4e219d6ad9d5e56e20afd7423092f506400a29e4 Bump min TS version to 5.0
- 65adeeacef0274abbda5438470a3d2bfd376256d v3.24.1
Implement @standard-schema/spec
This is the first version of Zod to implement the Standard Schema spec. This is a new community effort among several validation library authors to implement a common interface, with the goal of simplifying the process of integrating schema validators with the rest of the ecosystem. Read more about the project and goals here.
z.string().jwt()
Thanks to @Mokshit06 and @Cognition-Labs for this contribution!
To verify that a string is a valid 3-part JWT.
z.string().jwt();
⚠️ This does not verify your JWT cryptographically! It merely ensures its in the proper format. Use a library like
jsonwebtokento verify the JWT signature, parse the token, and read the claims.
To constrain the JWT to a specific algorithm:
z.string().jwt({ alg: "RS256" });
z.string().base64url()
Thank you to @marvinruder!
To complement the JWT validation, Zod 3.24 implements a standalone .base64url() string validation API. (The three elements of JWTs are base64url-encoded JSON strings.)
z.string().base64url()
This functionality is available along the standard z.string().base64() validator added in Zod 3.23.
z.string().cidr()
Thanks to @wataryooou for their work on this!
A validator for CIDR notation for specifying IP address ranges, e.g. 192.24.12.0/22.
z.string().cidr()
To specify an IP version:
z.string().cidr({ version: "v4" })
z.string().cidr({ version: "v6" })
View the full diff from 3.23.8: https://github.com/colinhacks/zod/compare/v3.23.8...v3.24.0
- 294f54f418bd1506d807b351213c66dbffd8ac31 Update README_ZH.md about Discriminated unions (#3493)
- 1247caf58d1c189155bd04c068be1c758ab77c1c Add Kubb as X-to-Zod community tool (#3508)
- 62b7842c46dd7f1004f41e2220284abb75378fb7 Update default branch
- c6bc80de5091c634a371cc81877df816a269e965 Fix issue #3582 : ULID should be case insensitive (#3593)
- a5b9dc34d4086e8e084a059f71a481618a336303 docs: add zod-schema-faker to ecosystem (#3605)
- 9818d0eba1a5877a2b1917296d018a8b4e31b211 Add zod-sockets (#3609)
- 7173d0bcc2105777102e22d36a2866196e2830f3 Add drizzle-zod library to X to Zod README.md section (#3648)
- c5a4edcaf7a7c434b0f94a18123750bd1151c2cf Add 'schemql' in Powered by Zod (#3800)
- 85916b32002e4302cccd77fcf64574f34f2e8595 docs: add zod-form-renderer to form integration docs (#3697)
- 51f1dc3950d93e4a1c11467b7e92069cd372d450 docs: add unplugin-environment in powered by zod (#3778)
- 8e74db34cd0c673d21fe3b8b62c9de4c785e3de2 fix: ipv6 regex validation (#3513)
- 1f4f0dacf313a2dba45563d78171e6f016096925 refactor: rename ip version types (#3755)
- f487d74ecd3ae703ef8932462d14d643e31658b3 Remove faulty ip test case
- 48f1c4793b21b19714d68f970ae3d739263e2b1d docs: Remove invalid semicolon in ERROR_HANDLING.md (#3857)
- 1d0a4b95300a2c470b175ed4524fe3cf04ef9b19 fix: bigint coerce crash (#3822)
- 14dceaa2d2b27ef448b48c4f0641413e3ead974d Add API library (#3814)
- f82f817252c1f1342d81a2a5ae9adf426cb32cec feat: z.string.cidr() - support CIDR notation (#3820)
- 71a0c33c01ca7e2be16e27f763ec1c3e9dee6943 docs: add info on unqualified local datetime strings (#3760)
- b85686ab852bc75919fd9d853dfca4b0968301dd Add support for
base64urlstrings (#3712) - 6407bed5a229f330b9353e086f7798f1422e2bb7 Allow creation of discriminated unions with a readonly array of options (#3535)
- 37551462f4a534f86e6190aafea1747b010eca7a Remove createParams cascade from .array() (#3530)
- 963386df253360fde67ca10c6bf47fec1fcc476a Fix lint
- 69a1798ce2df65555bda0a8978a6baadd7d5588e Implement Standard Schema spec (#3850)
- c1dd537baa9e4fad781ea365643399707fea91be Adds
frrmpackage to documentation (#3818) - b68c05fea12d8060000aa06abc1e95b08f061378 feat: Add JWT string validator (#3893)
Commits:
- 0f4d403558ae0490c711e4c2bfcf6c200bd14e11 Add Bronze logos (#3470)
- 19687315b5b24bbd1ff6c346bfc2975700221748 Tweak tiers (#3471)
- eda7df314399929f7ed737423868a5a0780cd944 Change RefinementCtx to interface
- ca42965df46b2f7e2747db29c40a26bcb32a51d5 v3.23.8
Commits:
- 29d2ea2a15f0b1ac4b89138041f786a3dafc490b Add copper
- d969423266fccee56ef769da6744cc8bacb04550 Fix #3437: extendShape erases JSDoc property documentation (#3463)
- 2239ff3ccc9af4d28bee27bd6fb2a5632844480b Add social crow
- f985b5b922cb357dbf4b25bb43814d19f838e046 3.23.7
Commits:
- bc0095aab9e7254deb18701adc63de128ca2c742 Test on latest node
- 6e5699a30373cc22879f2bcb6902fc138518c980 Lint on latest node
- 1f466d9d00f446d7bed1962990e7a1ce813ab0d4 describe how one can protect from cyclical objects starting an infini… (#3447)
- 3fed6f21e0ea7adc91aa0cc44f75bcf4e526d98e Add zod playground link (#3454)
- 04e1f379f6989d23dd45660fcabc78f76d7834f8 Fixed freezing async ZodReadonly results (#3457)
- b87e59d0e4bbb4403bf27243afdcda9fcdeec258 Update sponsor tiers (#3453)
- 143886151bba3930bdcc10d34a1cff4bf9103ba8 Add copper tier (#3460)
- ce3711e1384952d255769b9495f9bfadfb327291 add VSCode dev container support and documenation
- 93b480b12ec3466cbd3b4182f7ce292e5c61528c v3.23.6
Commits:
- 110b8211f991b3e060ab2da4fec7b63d600439ad Update README_ZH.md (#3433)
- c1910bdfc98709b8f14231e2cefc5a3be401e3ee Made ZodEnum take readonly string array (#3444)
- 541a862e978f96eb391849a6bf16be84231aa1b3 3.23.5
Commits:
- 157b18d742c86d85b26a8421af46ad6d6d6b6ea7 Add 3.23 announcement
- aedf93f1435a29463d915c3be45b4dcbeefa8cc1 Revert change to default Input
- 45107f7a7230fe48ee24dc37e621422c9dc64ec4 v3.23.4
Commits:
- 103d2436f85872ca0e0e6247652989cc93d46a39 3.23.3
Commits:
- c340558d14f5222a2ca177e0591463c06cc5edc3 Update protocol
- ef588d036f3e98b832796e9a681dbaf097631ea0 Fix t3env
- 9df70dd71195df951c43f180fbe5e64ea1f835df 3.23.2
This changes the default generics back to any to prevent breakages with common packager like @hookform/resolvers:
- class ZodType<Output = unknown, Def extends ZodTypeDef = ZodTypeDef, Input = unknown> {}
+ class ZodType<Output = any, Def extends ZodTypeDef = ZodTypeDef, Input = any> {}
Commits:
- 59f48723d36c423d9e10b3bd52325a7998314230 Change unknown -> any for ZodType defaults
- 2ff5ceb428634de0ea4501495039c05a8e95b60a 3.23.1
Zod 3.23 is now available. This is the final 3.x release before Zod 4.0. To try it out:
npm install zod
Features
z.string().date()
Zod can now validate ISO 8601 date strings. Thanks @igalklebanov! https://github.com/colinhacks/zod/pull/1766
const schema = z.string().date();
schema.parse("2022-01-01"); // OK
z.string().time()
Zod can now validate ISO 8601 time strings. Thanks @igalklebanov! https://github.com/colinhacks/zod/pull/1766
const schema = z.string().time();
schema.parse("12:00:00"); // OK
You can specify sub-second precision using the precision option:
const schema = z.string().time({ precision: 3 });
schema.parse("12:00:00.123"); // OK
schema.parse("12:00:00.123456"); // Error
schema.parse("12:00:00"); // Error
z.string().duration()
Zod can now validate ISO 8601 duration strings. Thanks @mastermatt! https://github.com/colinhacks/zod/pull/3265
const schema = z.string().duration();
schema.parse("P3Y6M4DT12H30M5S"); // OK
Improvements to z.string().datetime()
Thanks @bchrobot https://github.com/colinhacks/zod/pull/2522
You can now allow unqualified (timezone-less) datetimes using the local: true flag.
const schema = z.string().datetime({ local: true });
schema.parse("2022-01-01T12:00:00"); // OK
Plus, Zod now validates the day-of-month correctly to ensure no invalid dates (e.g. February 30th) pass validation. Thanks @szamanr! https://github.com/colinhacks/zod/pull/3391
z.string().base64()
Zod can now validate base64 strings. Thanks @StefanTerdell! https://github.com/colinhacks/zod/pull/3047
const schema = z.string().base64();
schema.parse("SGVsbG8gV29ybGQ="); // OK
Improved discriminated unions
The following can now be used as discriminator keys in z.discriminatedUnion():
ZodOptionalZodNullableZodReadonlyZodBrandedZodCatch
const schema = z.discriminatedUnion("type", [
z.object({ type: z.literal("A").optional(), value: z.number() }),
z.object({ type: z.literal("B").nullable(), value: z.string() }),
z.object({ type: z.literal("C").readonly(), value: z.boolean() }),
z.object({ type: z.literal("D").brand<"D">(), value: z.boolean() }),
z.object({ type: z.literal("E").catch("E"), value: z.unknown() }),
]);
Misc
- feature: allow falsy error message by @fernandollisboa in https://github.com/colinhacks/zod/pull/3178
- feature: add attribute message to enum validatiion by @fernandollisboa in https://github.com/colinhacks/zod/pull/3169
Breaking changes
There are no breaking changes to the public API of Zod. However some changes can impact ecosystem tools that rely on Zod internals.
ZodFirstPartySchemaTypes
Three new types have been added to the ZodFirstPartySchemaTypes union. This may impact some codegen libraries. https://github.com/colinhacks/zod/pull/3247
+ | ZodPipeline<any, any>
+ | ZodReadonly<any>
+ | ZodSymbol;
Unrecognized keys in .pick() and .omit()
This version fixes a bug where unknown keys were accidentally accepted in .pick() and omit(). This has been fixed, which could cause compiler errors in some user code. https://github.com/colinhacks/zod/pull/3255
z.object({
name: z.string()
}).pick({
notAKey: true // no longer allowed
})
Bugfixes and performance
- Bugfix: Enum.extract/exclude should not remove error mapping by @shaharke in https://github.com/colinhacks/zod/pull/3240
- Added latest stable Node and TypeScript versions to test matrix for up-to-date testing. by @m10rten in https://github.com/colinhacks/zod/pull/3278
- Add types to
ZodFirstPartySchemaTypesby @MatthijsMud in https://github.com/colinhacks/zod/pull/3247 - fix: make
inputof.required()readonly by @KATT in https://github.com/colinhacks/zod/pull/3301 - add never props to safe parse return types by @schicks in https://github.com/colinhacks/zod/pull/3295
- Reporting errors of the preprocess that is the second property of object by @yukukotani in https://github.com/colinhacks/zod/pull/2912
- Improve
addQuestionMarks, fix #2184 by @colinhacks in https://github.com/colinhacks/zod/pull/3352 - fix for njs by @dvv in https://github.com/colinhacks/zod/pull/3063
- only look in
srcforbun testby @rotu in https://github.com/colinhacks/zod/pull/3038 - Restrict .pick()/.omit() mask type to only known properties by @petrovmiroslav in https://github.com/colinhacks/zod/pull/3255
- Make EnumValues generic by @IlyaSemenov in https://github.com/colinhacks/zod/pull/2338
- perf: avoid unnecessary error maps by @xuxucode in https://github.com/colinhacks/zod/pull/2532
- Bugfix: z.record().parse should not filter out undefined values by @raik-casimiro in https://github.com/colinhacks/zod/pull/3251
- Use Set.has instead of Array.indexOf for enum comparison (perf improvement) by @jmike in https://github.com/colinhacks/zod/pull/2659
- [2888] fix emails with single quotes failing validation by @Mansehej in https://github.com/colinhacks/zod/pull/2889
- Bugfix: Commas are incorrectly allowed in email regex. by @mokemoko in https://github.com/colinhacks/zod/pull/3286
- Fix regex in cuid2 validation to be what cuid2 library expects by @etareduction in https://github.com/colinhacks/zod/pull/2961
- Make depcruise pass by @rotu in https://github.com/colinhacks/zod/pull/3037
- Faster ipv4 parsing by @colinhacks in https://github.com/colinhacks/zod/pull/3413
Docs and ecosystem
- chore: add pastel package to ecosystem by @jlarmstrongiv in https://github.com/colinhacks/zod/pull/2949
- added required styles. by @Ansh101112 in https://github.com/colinhacks/zod/pull/2955
- Feature/better chinese translate by @NWYLZW in https://github.com/colinhacks/zod/pull/2988
- Fix z.instanceof example by @alexnault in https://github.com/colinhacks/zod/pull/3003
- Add documentation to Zod enum exclude/extract functions by @shaharke in https://github.com/colinhacks/zod/pull/3044
- Add docs for coercing nullish values by @rbuetzer in https://github.com/colinhacks/zod/pull/3067
- Adds
zod-devutility to eco-system section by @schalkventer in https://github.com/colinhacks/zod/pull/3113 - Add zhttp library to docs by @evertdespiegeleer in https://github.com/colinhacks/zod/pull/3134
- fixed Readme typo in NaNs example by @RashJrEdmund in https://github.com/colinhacks/zod/pull/3181
- adds zod-config library to the ecosystem by @alexmarqs in https://github.com/colinhacks/zod/pull/3200
- docs: update link and description of conform integration by @g1eny0ung in https://github.com/colinhacks/zod/pull/3238
- Update README.md by @yugmade13 in https://github.com/colinhacks/zod/pull/3317
- feat: overhaul generics section of readme to include more details on z.ZodTypeAny usage by @braden-w in https://github.com/colinhacks/zod/pull/3321
- Fix small typos by @mmorearty in https://github.com/colinhacks/zod/pull/3336
- docs: update Chinese docs and correct some of the typos by @jiechen257 in https://github.com/colinhacks/zod/pull/3338
- docs: improve chinese readme by @luckrnx09 in https://github.com/colinhacks/zod/pull/3371
- Add java-to-zod in X to Zod section by @ivangreene in https://github.com/colinhacks/zod/pull/3385
- docs: add
orvalto "X to Zod" ecosystems by @soartec-lab in https://github.com/colinhacks/zod/pull/3397
New Contributors
- @jlarmstrongiv made their first contribution in https://github.com/colinhacks/zod/pull/2949
- @Ansh101112 made their first contribution in https://github.com/colinhacks/zod/pull/2955
- @NWYLZW made their first contribution in https://github.com/colinhacks/zod/pull/2988
- @alexnault made their first contribution in https://github.com/colinhacks/zod/pull/3003
- @shaharke made their first contribution in https://github.com/colinhacks/zod/pull/3044
- @rbuetzer made their first contribution in https://github.com/colinhacks/zod/pull/3067
- @schalkventer made their first contribution in https://github.com/colinhacks/zod/pull/3113
- @evertdespiegeleer made their first contribution in https://github.com/colinhacks/zod/pull/3134
- @RashJrEdmund made their first contribution in https://github.com/colinhacks/zod/pull/3181
- @alexmarqs made their first contribution in https://github.com/colinhacks/zod/pull/3200
- @JonnyBurger made their first contribution in https://github.com/colinhacks/zod/pull/3214
- @fernandollisboa made their first contribution in https://github.com/colinhacks/zod/pull/3178
- @g1eny0ung made their first contribution in https://github.com/colinhacks/zod/pull/3238
- @m10rten made their first contribution in https://github.com/colinhacks/zod/pull/3278
- @MatthijsMud made their first contribution in https://github.com/colinhacks/zod/pull/3247
- @yugmade13 made their first contribution in https://github.com/colinhacks/zod/pull/3317
- @braden-w made their first contribution in https://github.com/colinhacks/zod/pull/3321
- @mmorearty made their first contribution in https://github.com/colinhacks/zod/pull/3336
- @schicks made their first contribution in https://github.com/colinhacks/zod/pull/3295
- @yukukotani made their first contribution in https://github.com/colinhacks/zod/pull/2912
- @jiechen257 made their first contribution in https://github.com/colinhacks/zod/pull/3338
- @luckrnx09 made their first contribution in https://github.com/colinhacks/zod/pull/3371
- @dvv made their first contribution in https://github.com/colinhacks/zod/pull/3063
- @rotu made their first contribution in https://github.com/colinhacks/zod/pull/3038
- @petrovmiroslav made their first contribution in https://github.com/colinhacks/zod/pull/3255
- @ivoilic made their first contribution in https://github.com/colinhacks/zod/pull/2364
- @telemakhos made their first contribution in https://github.com/colinhacks/zod/pull/3388
- @bchrobot made their first contribution in https://github.com/colinhacks/zod/pull/2522
- @szamanr made their first contribution in https://github.com/colinhacks/zod/pull/3391
- @ivangreene made their first contribution in https://github.com/colinhacks/zod/pull/3385
- @xuxucode made their first contribution in https://github.com/colinhacks/zod/pull/2532
- @raik-casimiro made their first contribution in https://github.com/colinhacks/zod/pull/3251
- @jmike made their first contribution in https://github.com/colinhacks/zod/pull/2659
- @Mansehej made their first contribution in https://github.com/colinhacks/zod/pull/2889
- @mokemoko made their first contribution in https://github.com/colinhacks/zod/pull/3286
- @etareduction made their first contribution in https://github.com/colinhacks/zod/pull/2961
- @mastermatt made their first contribution in https://github.com/colinhacks/zod/pull/3265
- @soartec-lab made their first contribution in https://github.com/colinhacks/zod/pull/3397
Full Changelog: https://github.com/colinhacks/zod/compare/v3.22.4...v3.23.0
Commits:
- d931ea3f0f15a6ae64f5f68e3c03912dffb2269d Lint
- 8e634bd600093b7161487bed705279c892395118 Fix prettier
- 4018d88f0e94992b2987428c4fda387b99ae2a53 docs: add @sanity-typed/zod to ecosystem (#2731)
- 15ba5a4d4cb5be5af23771de0ba1346b4ba20a0e docs: add
zod-sandboxto README ecosystem links (#2707) - 699ccae13b875d4fcadac268fd789c93b6ce8aef Export jsdoc with
@deprecatedwhen building (#2717) - dfe3719eae250ab3eca2d276da6c292867899cc6 Fix sanity-typed links (#2840)
- cd7991e04a550868bfcb5b5d46e5eb5bc7edf5f3 fix ulid regex (#2225)
- 7cb4ba2f85dd6b28290dda5de80ed54dfd2a793c Remove stalebot
- 9340fd51e48576a75adc919bff65dbc4a5d4c99b Lazy emojiRegex
- e7a9b9b3033991be6b4225f1be21da39c250bbb0 3.22.4
Commits:
- 1e23990bcdd33d1e81b31e40e77a031fcfd87ce1 Commit
- 9bd3879b482f139fd03d5025813ee66a04195cdd docs: remove obsolete text about readonly types (#2676)
- f59be093ec21430d9f32bbcb628d7e39116adf34 clarify datetime ISO 8601 (#2673)
- 64dcc8e2b16febe48fa8e3c82c47c92643e6c9e3 Update sponsors
- 18115a8f128680b4526df58ce96deab7dce93b93 Formatting
- 28c19273658b164c53c149785fa7a8187c428ad4 Update sponsors
- ad2ee9ccf723c4388158ff6b8669c2a6cdc85643 2718 Updated Custom Schemas documentation example to use type narrowing (#2778)
- ae0f7a2c15e7741ee1b23c03a3bfb9acebd86551 docs: update ref to discriminated-unions docs (#2485)
- 2ba00fe2377f4d53947a84b8cdb314a63bbd6dd4 [2609] fix ReDoS vulnerability in email regex (#2824)
- 1e61d76cdec05de9271fc0df58798ddf9ce94923 3.22.3
Commits:
- 13d9e6bda286cbd4c1b177171273695d8309e5de Fix lint
- 0d49f10b3c25a8e4cbb6534cc0773b195c56d06d docs: add typeschema to ecosystem (#2626)
- 8e4af7b56df6f2e3daf0dd825b986f1d963025ce X to Zod: add app.quicktype.io (#2668)
- 792b3ef0d41c144cd10641c6966b98dae1222d82 Fix superrefine types
Commits:
Fix handing of this in ZodFunction schemas. The parse logic for function schemas now requires the Reflect API.
const methodObject = z.object({
property: z.number(),
method: z.function().args(z.string()).returns(z.number()),
});
const methodInstance = {
property: 3,
method: function (s: string) {
return s.length + this.property;
},
};
const parsed = methodObject.parse(methodInstance);
parsed.method("length=8"); // => 11 (8 length + 3 property)
- 932cc472d2e66430d368a409b8d251909d7d8d21 Initial prototype fix for issue #2651 (#2652)
- 0a055e726ac210ef6efc69aa70cd2491767f6060 3.22.1
ZodReadonly
This release introduces ZodReadonly and the .readonly() method on ZodType.
Calling .readonly() on any schema returns a ZodReadonly instance that wraps the original schema. The new schema parses all inputs using the original schema, then calls Object.freeze() on the result. The inferred type is also marked as readonly.
const schema = z.object({ name: string }).readonly();
type schema = z.infer<typeof schema>;
// Readonly<{name: string}>
const result = schema.parse({ name: "fido" });
result.name = "simba"; // error
The inferred type uses TypeScript's built-in readonly types when relevant.
z.array(z.string()).readonly();
// readonly string[]
z.tuple([z.string(), z.number()]).readonly();
// readonly [string, number]
z.map(z.string(), z.date()).readonly();
// ReadonlyMap<string, Date>
z.set(z.string()).readonly();
// ReadonlySet<Promise<string>>
Commits:
- 6dad90785398885f7b058f5c0760d5ae5476b833 Comments
- 56ace682e4cc89132c034a3ae2c13b2d5b1a0115 Fix deno test
- 3809d54fc8c5dd0a0ce367bd2575fe3fdadf087d Add superforms
- d1ad5221900af640bc3093a2fb0476ec0c94953e Add transloadit
- a3bb701757127ffe05e773a2e449136b9b7efcb3 Testing on Typescript 5.0 (#2221)
- 51e14beeab2f469fcbf18e3df44653e1643f5487 docs: update deprecated link (#2219)
- a263814fc430db8d47430cd2884d2cea6b11c671 fixed Datetime & IP TOC links
- 502384e56fe2b1f8173735df6c3b0d41bce04edc docs: add mobx-zod-form to form integrations (#2299)
- a8be4500851923aa865e009fe9c2855e80482047 docs: Add
zockerto Ecosystem section (#2416) - 15de22a3ba6144c7d8d2276e8e56174bcdfa7225 Allow subdomains and hyphens in
ZodString.email(#2274) - 00f5783602ccbe423deb0dbd76ecf13a276bc54d Add
zod-openapito ecosystem (#2434) - 0a17340e9fc4b909d10ca3687b6bc6454903ff21 docs: fix minor typo (#2439)
- 60a21346086d32ca9f39efc2771f5db37c835c03 Add masterborn
- 0a90ed1461dafa62ff50ce0d5d5434fd4a2a4a20 chore: move
exports.typesfield to first spot @ package.json. (#2443) - 67f35b16692ca33fd48adfec9ae83b9514f8a4b7 docs: allow Zod to be used in dev tools at site (#2432)
- 6795c574b1d34f6e95ae891f96d8b219b98ace92 Fix not working Deno doc link. (#2428)
- 37e9c550460e4edd144da90d903e878c119c5cc1 Generalize uuidRegex
- 09699501ff6218b3b0a7e382eca3c02a8226ce13 adds ctx to preprocess (#2426)
- af08390139cf9fd4fc9e398b60a39191bf224076 fix: super refinement function types (#2420)
- 36fef58410f4b2c9e79edabae2fc567a4aee13a7 Make email regex reasonable (#2157)
- f627d14d3bfe3a680ac0d54705b2e63daa912aed Document canary
- e06321c15d22082e47c7c111a92ec7b3e104c644 docs: add tapiduck to API libraries (#2410)
- 11e507c4d3bf4ad3ab2057a0122168ed0048a2c4 docs: add ts as const example in zod enums (#2412)
- 5427565c347a14056bc60e3ffd800b98753952bc docs: add zod-fixture to mocking ecosystem (#2409)
- d3bf7e60a8eb706c4c63a9a91fd66565b82883cf docs: add
zodockto mocking ecosystem (#2394) - 2270ae563f7f14bed770f75d9c252880794fa71f remove "as any" casts in createZodEnum (#2332)
- 00bdd0a7ffdf495af14e67ae1396c85a282c38dd fix proto pollution vulnerability (#2239)
- a3c525658bc43edf40747a99b8f882d8d3d1e0c7 Fix error_handling unrecognized_keys example
- 4f75cbc682199a5411189f9cd9abba9af4924746 Adds getters to Map for key + value (#2356)
- ca7b03222764496d72085b1178fa22f4a57fe579 FMC (#2346)
- 6fec8bd3407f463f157522a3979b4d202870ba4c docs: fix typo in link fragment (#2329)
- 16f90bd22b465aca9a1fbad09248d80aa93fd824 Update README.md
- 2c802507d92d2d2e15be959695b1de78b896bfcb Update readme
- eaf64e09ba1a87dd6bf348fb97061894a01242d2 Update sponsors
- c5763112e2912390f3317d738e4261fa8747494e Update readme
- 5e23b4fae4715c7391f9ceb4369421a034851b4c Add
*.mdpattern to prettier (#2476) - 898dced470f1045b5469543abd2f427a713d93eb Revamp tests
- 6309322a28545e316299f8b9a36f43132d347300 Update test runners
- c0aece1672d1442d69ce1991142af8f16ed20ecb Add vitest config
- 73a5610186c413872153e8dcac76c4c4f23dfe4e Update script
- 8d8e1a2d306cecaf3d8cb88f32fe3e130a834f9f Fix deno test bug
- 9eb2508fac78cc36faefd050e9616bb6d34814c1 Clean up configs
- cfbc7b3f6714ced250dd4053822faf472bf1828e Fix root jest config
- 8677f688b0ab1bb5991e90744f46a15082772bd6 docs(comparison-yup): Yup added partial() and deepPartial() in v1 (#2603)
- fb00edd04ca338b8d791a96dead161076538c6c2 docs: add VeeValidate form library for Vue.js (#2578)
- ab8e71793431eeb163613007c134132e6c2ab078 docs: fix typo in z.object (#2570)
- d870407a020f9518fbae662f9f48a9aba005a3e2 docs: fix incomplete Records example (#2579)
- 5adae24e9b2fc98fc679defa8f78e4142d4c3451 docs: add conform form integration (#2577)
- 8b8ab3e79691ebafbb9aac3ce089eaf0dcd6d8fe Update README.md (#2562)
- 6aab9016873c12be08d19bcc097b3e5ba4c9d6fe fix typo test name (#2542)
- 81a89f593f4d6b05f770bbb3ad0fc98075f468dd Update nullish documentation to correct chaining order (#2457)
- 78a409012a4dc34a455f5c4a7e028ca47c921e1b docs: update comparison with
runtypes(#2536) - 1ecd6241ef97b33ce229b49f1346ffeee5d0ba74 Fix prettier
- 981d4b5e272e7e35ff44a31fbb5e8e90594b1933 Add ZodReadonly (#2634)
- fba438cddea800b081a15aefc8b1efea2eccf7af 3.22.0
Commits:
- 22f3cc6ed52a28c984a0319a1a03e1af244cee02 3.21.4
Commits:
- 14c08d87129c3b652f03d2e724979c383c55e0b4 added more
.pipeexamples - 006e6521f425b38e1fbb898e29921fe885caf7ba Fix npm canary action paths pattern (#2148)
- bdcff0f20f4c35dd6a44b1324711dfd34a41ae96 Remove logging in tests
- a5830c6d3fe28f0d5435cc9ff22846be7f5977c1 Reverted #1564
- c4583819e77a702e21b587c4bf081d0292f2b754 Fix tests
- 2db0dcadc961fd57f7f10f9d9f55d67e6d040342 3.21.3
Commits:
- b276d71eaefef6cb87c81e8429bd160e4b68c168 Improve typings in generics
- 4d016b772b79d566bfa2a0c2fc5bfbd92b776982 Improve type inference in generics
- f9895ab1650ef3df9c598a8c43ede0160596ac2e Improve types inside generic functions
- ac0135e00df75abd57a93a4816fe0fdaa31e94e8 Pass input into catchValue
Features
Support for ULID validation
z.string().ulid();
Commits:
- 4f8946182ee07eb7b5d40efa908b1715414e8929 Prettier
- bd6527a47a4626135dccac113a7b09f81b675edd Update deps
- 126c77b3130d9a68032f72ac76dd9e1ccfd86c2c added
toLowerCaseandtoUpperCaseback in for v3.21.0 - 174965739d17db348d445ab250fb2cf6bd7cdd51 Update README.md
- dabe63d15eb6d22246aa5d5c83b69d1d5f4c2f4b updated
z.customexample again :D - 6b8f6557d9b53ea7ad3fda753a51cdf153ba1fb7 docs: improve cn readme (#2143)
- 9012dc7055e1467b6d619a6c0ad016fdfbde2b9c add
.includes(value, options?)@ZodString. (#1887) - 67b981e70b4bacb2278a9aacd22d38cbb4b52d17 Make safeParse().error a getter
- 346fde03724bfd1601823e4f72470bc7e344030b 3.21.0-canary.20230304T235951
- b50d871b2f5949587afdcce2375227a447dbb742 Add canary release CI
- b20cca230a6a9beb8acf841250641b62847b6e80 Fix canary
- f7f5c50c65d7c7e5262c028e6832b92b14d84ea5 Move action to .github/workflows
- f01fa0e48ca18630604366f5bc7401a18eb4d018 Try to fix canary CI
- f5e8067b2afcc3e5ae9f8ed389a31b83a7c3ceec No git tag
- 5b304ae41705105ae6edcacdb6dfdac9c527b3f4 No dry run
- 20df80e6ce2ac27f6e2f26b61cd1fd4c942b152d Add tsc compilation test
- ead93d3cfde54efe952dc615c21ff179a00f7574 Document .pipe()
- d8e86534325fb00bc0193a4c6af04f2a67bd2e4e Update headers
- 03c0ab1640ca9111d9fbac3c261e2f76e3cbf247 Cache the evaluation of ParseInputLazyPath.path() for a moderate perf improvement (#2137)
- e7b3b7bf493caeee7e4f043eea024e4d3badc090 Improve string docs
- 83478f5e413c333f07f53b9b4bb8c24b75e1cecf Remove zod dep
- 2f1868d0c17c0e401c4438d9d35e68f9685a741b Specify paths for canary
- e599966709fe0253d6779ce1dec38a2adcebf41f Add sponsors
- 950bd17f01668b45e592a678974437b15012b158 Tweak x.custom example
- 728e56a7e157cca8cdc0ab937f25a2412673c934 Close #2127
- 64883e4fe41b10eb577c4f9eaf6f24fa29bcd60d feat: z.string().ulid() - add support for ulids (#2049)
- e0d709b1348efab06ac5341d360a411bc09eb7ba 3.20.1
- 9c3319443cfc953adc51786e8d6fe0bbe1e37f8e Remove comments, clean up utils
- 942e2db8e51d580f4e3cd8c4c4af8bc6aecf4130 Fix tests
Features
z.string().emoji()
Thanks @joseph-lozano for https://github.com/colinhacks/zod/pull/2045! To validate that all characters in a string are emoji:
z.string().emoji()
...if that's something you want to do for some reason.
z.string().cuid2()
Thanks @joulev for https://github.com/colinhacks/zod/pull/1813! To validate CUIDv2:
z.string().cuid2()
z.string().ip()
Thanks @fvckDesa for https://github.com/colinhacks/zod/pull/2066. To validate that a string is a valid IP address:
const v4IP = "122.122.122.122";
const v6IP = "6097:adfa:6f0b:220d:db08:5021:6191:7990";
// matches both IPv4 and IPv6 by default
const ipSchema = z.string().ip();
ipSchema.parse(v4IP) // pass
ipSchema.parse(v6IP) // pass
To specify a particular version:
const ipv4Schema = z.string().ip({ version: "v4" });
const ipv6Schema = z.string().ip({ version: "v6" });
z.bigint().{gt|gte|lt|lte}()
Thanks @igalklebanov for #1711! ZodBigInt gets the same set of methods found on ZodNumber:
z.bigint().gt(BigInt(5));
z.bigint().gte(BigInt(5));
z.bigint().lt(BigInt(5));
z.bigint().lte(BigInt(5));
z.bigint().positive();
z.bigint().negative();
z.bigint().nonnegative();
z.bigint().nonpositive();
z.bigint().multipleOf(BigInt(5));
z.enum(...).extract() and z.enum(...).exclude()
Thanks @santosmarco-caribou for https://github.com/colinhacks/zod/pull/1652! To add or remove elements from a ZodEnum:
const FoodEnum = z.enum(["Pasta", "Pizza", "Tacos", "Burgers", "Salad"]);
const ItalianEnum = FoodEnum.extract(["Pasta", "Pizza"]); // ZodEnum<["Pasta", "Pizza"]>
const UnhealthyEnum = FoodEnum.exclude(["Salad"]); // ZodEnum<["Pasta", "Pizza", "Tacos", "Burgers"]>
This API is inspired by the Exclude and Extract TypeScript built-ins.
Pass a function to .catch()
Thanks @0xWryth for https://github.com/colinhacks/zod/pull/2087! The .catch() method now accepts a function that receives the caught error:
const numberWithErrorCatch = z.number().catch((ctx) => {
ctx.error; // ZodError
return 42;
});
Compiler performance
Zod 3.20.2 introduced an accidental type recursion that caused long compilation times for some users. These kinds of bugs are very hard to diagnose. Big shoutout to @gydroperit for some heroic efforts here: https://github.com/colinhacks/zod/pull/2107 Zod 3.21 resolves these issues:
- https://github.com/colinhacks/zod/issues/2142
- https://github.com/colinhacks/zod/issues/1741
- https://stackoverflow.com/questions/74881472/slow-typescript-autocompletion-in-vs-code-for-zod
Commits:
- 3c54461d7a649bf727aec59367eefb214ffe24fe fix typo in readme
- c244fb6c57506fd11609106960639de26ddf9b6d feat: z.string().emoji() (#2045)
- 39cbb6971c3dca09cbc0acdca2d3995dfd26aab2 Fix emoji validation, fix lint
- d8f07bbfffd255b0aee6b5fe9bb6aa2bce6586af Fix emoji
- 9b7dd816e92e16ca735e488b77e280a92a84ed64 Improve variable name clarity (#2048)
- 5cec1871ac21627608af6c07585d5e50ff30f281 Add documentation for the param parameter of z.custom
- 654f52969a968c630af816dcad0d8f3721f9001a Merge pull request #2057 from trygveaa/add-documentation-for-z-custom-params
- 981af6503ee1be530fe525ac77ba95e1904ce24a Merge pull request #2019 from vbud/patch-1
- a7c2969b9125df0fbfa65e8541a974eeaf53b6a6 Update error_handling
- 8f3d0283ba75d146d5199fe3dc140eeb5402352c BRAND Record to Non Partial (#2097)
- 5ec98e1c4420957f93a7388bf49fb01d91bcbcd0 Fix email issues in pull request #1982 (#2058)
- 7d40ba58931130ec965be9d65d14e0665ee9c379 feat(#2059): z.string.ip() - add support for IP address (#2066)
- e5596054cfddf8aa1ba8d7d3bad63552a2bf9b6a feat: add
.catcherror (#2087) - defdab9c163d9a994f927a0644ab4ec172513fcb Fix record tests
- 8de36eb17d9477ada75cea2164d6b47079dd0444 FIX: emoji regex and tests (#2090)
- 16beeb598039b33bc5a209956042d858abacca34 lowercase method for ZodString (#2038)
- 75cb9e814115a35c0b4cc2e970f6aaae90e1a13c add checks @
ZodBigInt. (#1711) - c4d4e494227aadc752d4d5a5a317ec16bb6f5a45 Update ERROR_HANDLING.md (#2022)
- d6f08908b17ea10456befc2231a867d5cea02a0e added link to deno land
- 4cf19606870e66bf4307984bf99a4bef495c7818 Refactoring of ZodFormattedError type to improve tsc check time (#2107)
- 867a921a93160780d9f3aeddabf1ca49758a3c1e Bump http-cache-semantics from 4.1.0 to 4.1.1 (#1985)
- edc3a67e77d33979b3ee9e071557b4ca53298c55 Deprecate deepPartial
- e59f639d3bb5cca65ef239d5dd5c93e74ce4a801 Add custom tests
- a6b44ed8e346af2fabbb62b5164b99a387accd32 Remove logging
- a1fc3fb815051beb4b7030969828aa6abe469c2c commented out
toLowerCaseandtoUpperCase - e71cc523b1865568c4db45f82789e5c86bed0f12 Update README_ZH.md (#2139)
- 3af38fbe2cb114219e688103e41e382e28ec7a80 add
ZodNumber.safe()&ZodNumber.isSafe. (#1753) - 6ef82ee1e45dbcfc92a2ed359b1d2ae87d54c43d Add benchmark flags
- 5463593385549452768e060a98cc0fd8988760d2 Support brands in recursive types
- 80745238937adc06c5b4eab19ef273ca9f7f2de8 Update readme
- b6794a4981b8621fee84642f5313464f5e8f9a22 Add index signature for passthrough
- 3c6cdd245ab73d7ca1461a18b5be2da07abe6b6b Make generic optional in objectOutputType
- bc43ad18e64cf7add23e90bc6b07d5bba8370e5e Fix rollup build
- 6a0545acd5b9cfc40b0b3f04e64bfc5dd789d1b1 3.21.0
- 7c0733968d64c7d7aebc1ae54ca90aadcb2bffc3 Fix brand
- 0aa6021ef3628bb39715bdda416be2c6a4951141 Clean up tests
Commits:
- e6939195fbb5191402ba3d6f5b7aade463de6e51 3.20.6
Commits:
- e71c7be15e393e0932aa3c939d061f8444f6ae29 Fix extract/exclude type error
Commits:
- b8d731f779679e6f47cde18b2c422b0d4f44b01d Set input type of ZodCatch to unknown
- 06c237c29f53a827d2eb29cb20e9e23caba1ce2c Revert merge changes
- c8ce27e8c0378856964cf8892c6102bde63fa0cb 3.20.4
Features
- Add string cuid2() validation by @joulev in https://github.com/colinhacks/zod/pull/1813
- Add
ZodNumber.isFinite, makeZodNumber.isInttrue if.multipleOf(int). by @igalklebanov in https://github.com/colinhacks/zod/pull/1714 - feat: Add
extract/excludemethods toZodEnumby @santosmarco-caribou in https://github.com/colinhacks/zod/pull/1652
Fixes and documentation
- add more test cases for
z.coerce. by @igalklebanov in https://github.com/colinhacks/zod/pull/1680 - Add Modular Forms to form integrations in README by @fabian-hiller in https://github.com/colinhacks/zod/pull/1695
- docs: Instruct users to return z.NEVER in .superRefine() when providing a type predicate by @zetaraku in https://github.com/colinhacks/zod/pull/1742
- Fix small typo in ERROR_HANDLING.md by @t-shiratori in https://github.com/colinhacks/zod/pull/1720
- Improve accuracy of the
isAsynctype guard by @aaronccasanova in https://github.com/colinhacks/zod/pull/1719 - fix: Fix
ZodCatchby @santosmarco-caribou in https://github.com/colinhacks/zod/pull/1733 - Fix datetime offset without comma by @ooga in https://github.com/colinhacks/zod/pull/1749
- Discriminated union example fails to parse by @matthewfallshaw in https://github.com/colinhacks/zod/pull/1713
- fix: [#1693] Tuple with empty items by @metuan in https://github.com/colinhacks/zod/pull/1712
- fix: #1668 email regex safari compat by @AnatoleLucet in https://github.com/colinhacks/zod/pull/1683
- docs: fix typo by @zetaraku in https://github.com/colinhacks/zod/pull/1699
- fix installation links in table of contents by @DetachHead in https://github.com/colinhacks/zod/pull/1700
- Updated
deno/lib/README.mdto matchzod/README.mdby @JacobWeisenburger in https://github.com/colinhacks/zod/pull/1791 - fix(#1743): Fix passing params in root class by @santosmarco-caribou in https://github.com/colinhacks/zod/pull/1756
- change the chaining order of nullish method by @p10ns11y in https://github.com/colinhacks/zod/pull/1702
- Propagate custom error type to ZodFormattedError subfields by @carlgieringer in https://github.com/colinhacks/zod/pull/1617
- fix deno literal test. by @igalklebanov in https://github.com/colinhacks/zod/pull/1794
- Document
.describe()by @rattrayalex in https://github.com/colinhacks/zod/pull/1819 - update homepage link in package.json by @Gpx in https://github.com/colinhacks/zod/pull/1830
- fix: compile error in sample code by @jtgi in https://github.com/colinhacks/zod/pull/1822
- Readme: Move "Coercion for primitives" section by @tordans in https://github.com/colinhacks/zod/pull/1842
- Readme: Add internal links "or" <-> "union" by @tordans in https://github.com/colinhacks/zod/pull/1846
- Readme: Add example for string validation for an optional field to chapter "Unions" by @tordans in https://github.com/colinhacks/zod/pull/1849
- Readme: Add intro to chapter Literals by @tordans in https://github.com/colinhacks/zod/pull/1877
- fix: faker.js link in readme by @markacola in https://github.com/colinhacks/zod/pull/1843
- Minor typo fix by @iamchandru6470 in https://github.com/colinhacks/zod/pull/1945
- chore(documentation): Update CHANGELOG to redirect to Github Releases by @mitchwd in https://github.com/colinhacks/zod/pull/1936
- fix: [#1839] remove caught errors from issues by @maxArturo in https://github.com/colinhacks/zod/pull/1926
- fix: [#1784] dark mode in the documentation by @fvckDesa in https://github.com/colinhacks/zod/pull/1932
- Allow also "[+-]hh" as datetime offset by @rafw87 in https://github.com/colinhacks/zod/pull/1797
- Feature/add resolves method to zod promise by @bolencki13 in https://github.com/colinhacks/zod/pull/1871
- test: add benchmark tests for date and symbol by @pnts-se in https://github.com/colinhacks/zod/pull/1796
- export the email regex by @andresBobsled in https://github.com/colinhacks/zod/pull/2007
- Add React form validation library to ecosystem by @crutchcorn in https://github.com/colinhacks/zod/pull/1999
- fix: make sure only mask keys with truthy values are respected at runtime @
.pick,.omit,.partial&.required. by @igalklebanov in https://github.com/colinhacks/zod/pull/1875 - fix: failing prettier checks on merge by @maxArturo in https://github.com/colinhacks/zod/pull/1969
- deny unexpected keys @
ZodObject's.omit(mask),.pick(mask),.required(mask)&.partial(mask)at compile time. by @igalklebanov in https://github.com/colinhacks/zod/pull/1564 - docs: punctuation by @jly36963 in https://github.com/colinhacks/zod/pull/1973
- fix[#1979]: Increment Email validation by @fvckDesa in https://github.com/colinhacks/zod/pull/1982
- test: additional unit-tests for object by @pnts-se in https://github.com/colinhacks/zod/pull/1729
New Contributors
- @fabian-hiller made their first contribution in https://github.com/colinhacks/zod/pull/1695
- @zetaraku made their first contribution in https://github.com/colinhacks/zod/pull/1742
- @t-shiratori made their first contribution in https://github.com/colinhacks/zod/pull/1720
- @aaronccasanova made their first contribution in https://github.com/colinhacks/zod/pull/1719
- @ooga made their first contribution in https://github.com/colinhacks/zod/pull/1749
- @matthewfallshaw made their first contribution in https://github.com/colinhacks/zod/pull/1713
- @metuan made their first contribution in https://github.com/colinhacks/zod/pull/1712
- @AnatoleLucet made their first contribution in https://github.com/colinhacks/zod/pull/1683
- @DetachHead made their first contribution in https://github.com/colinhacks/zod/pull/1700
- @p10ns11y made their first contribution in https://github.com/colinhacks/zod/pull/1702
- @carlgieringer made their first contribution in https://github.com/colinhacks/zod/pull/1617
- @rattrayalex made their first contribution in https://github.com/colinhacks/zod/pull/1819
- @Gpx made their first contribution in https://github.com/colinhacks/zod/pull/1830
- @jtgi made their first contribution in https://github.com/colinhacks/zod/pull/1822
- @tordans made their first contribution in https://github.com/colinhacks/zod/pull/1842
- @markacola made their first contribution in https://github.com/colinhacks/zod/pull/1843
- @iamchandru6470 made their first contribution in https://github.com/colinhacks/zod/pull/1945
- @mitchwd made their first contribution in https://github.com/colinhacks/zod/pull/1936
- @fvckDesa made their first contribution in https://github.com/colinhacks/zod/pull/1932
- @rafw87 made their first contribution in https://github.com/colinhacks/zod/pull/1797
- @bolencki13 made their first contribution in https://github.com/colinhacks/zod/pull/1871
- @joulev made their first contribution in https://github.com/colinhacks/zod/pull/1813
- @pnts-se made their first contribution in https://github.com/colinhacks/zod/pull/1796
- @andresBobsled made their first contribution in https://github.com/colinhacks/zod/pull/2007
- @crutchcorn made their first contribution in https://github.com/colinhacks/zod/pull/1999
- @jly36963 made their first contribution in https://github.com/colinhacks/zod/pull/1973
Full Changelog: https://github.com/colinhacks/zod/compare/v3.20.2...v3.20.3
Commits:
- d7d49e77ccd758ee874f7866862840f88f75cbb6 Clarify boolean coercion
- f49cbcb38f7e58e37480ded0f8f558c85de1ce3a Fix formatting
- 0b62f8c0c1722a15bd8afbc003e78fe7a177b2a2 Revert email regex changes
- 68919aa1790fcb729385a4b290ee03b3d8df0d86 3.20.2
- c9e4ed4095d77f5b43a5ba11d8f76b56ea48e5c6 Fix string test
Commits:
- 1298d26115e09cf097cb272cfc3184484eb64fd1 Update readme
- b3b0ecfcb8d2314cf3e6cbd78056c5410650c348 Only call .catch() method when parsing fails (#1674)
- 957b55b82d19707888a4914670c8cf8563911425 Fixing ZodString::isDatetime. (#1678)
- 29ec1f8d99836d8bb0661cac8641d4b4094aaf40 Add default
- 1161b8f77e8ef120f9a0fca6e1ca223538d8ffc4 3.20.1
Breaking changes
There are no breaking API changes, however TypeScript versions 4.4 and earlier are no longer officially supported.
New features
The most feature-packed release since Zod 3.0!
.pipe()
A new schema method .pipe() is now available on all schemas. which can be used to chain multiple schemas into a "validation pipeline". Typically this will be used in conjunction with .transform().
z.string()
.transform(val => val.length)
.pipe(z.number().min(5))
The .pipe() method returns a ZodPipeline instance.
z.coerce
Zod now provides a more convenient way to coerce primitive values.
const schema = z.coerce.string();
schema.parse("tuna"); // => "tuna"
schema.parse(12); // => "12"
schema.parse(true); // => "true"
During the parsing step, the input is passed through the String() function, which is a JavaScript built-in for coercing data into strings. Note that the returned schema is a ZodString instance so you can use all string methods.
z.coerce.string().email().min(5);
All primitive types support coercion.
z.coerce.string(); // String(input)
z.coerce.number(); // Number(input)
z.coerce.boolean(); // Boolean(input)
z.coerce.bigint(); // BigInt(input)
z.coerce.date(); // new Date(input)
.catch()
A new schema method .catch() is now available on all schemas. It can be used to provide a "catchall" value that will be returned in the event of a parsing error.
const schema = z.string().catch("fallback");
schema.parse("kate"); // => "kate"
schema.parse(4); // => "fallback"
The .catch() method returns a ZodCatch instance.
z.symbol()
A long-missing hole in Zod's type system is finally filled! Thanks @santosmarco-caribou.
const schema = z.symbol();
schema.parse(Symbol('asdf'));
Relatedly, you can also pass symbols into z.literal().
const TUNA = Symbol("tuna");
const schema = z.literal(TUNA);
schema.parse(TUNA); // Symbol(tuna)
schema.parse(Symbol("nottuna")); // Error
z.string().datetime()
A new method has been added to ZodString to validate ISO datetime strings. Thanks @samchungy!
z.string().datetime();
This method defaults to only allowing UTC datetimes (the ones that end in "Z"). No timezone offsets are allowed; arbitrary sub-second precision is supported.
const dt = z.string().datetime();
dt.parse("2020-01-01T00:00:00Z"); // 🟢
dt.parse("2020-01-01T00:00:00.123Z"); // 🟢
dt.parse("2020-01-01T00:00:00.123456Z"); // 🟢 (arbitrary precision)
dt.parse("2020-01-01T00:00:00+02:00"); // 🔴 (no offsets allowed)
Offsets can be supported with the offset parameter.
const a = z.string().datetime({ offset: true });
a.parse("2020-01-01T00:00:00+02:00"); // 🟢 offset allowed
You can additionally constrain the allowable precision. This specifies the number of digits that should follow the decimal point.
const b = z.string().datetime({ precision: 3 })
b.parse("2020-01-01T00:00:00.123Z"); // 🟢 precision of 3 decimal points
b.parse("2020-01-01T00:00:00Z"); // 🔴 invalid precision
z.number().finite()
Restrict a number schema to finite values. Thanks @igalklebanov.
const schema = z.number().finite();
schema.parse(5); 🟢
schema.parse(Infinity); 🔴
schema.parse(-Infinity); 🔴
What's Changed
- Add
maskparameter to.requiredmethod by @SrBrahma in https://github.com/colinhacks/zod/pull/1315 - Added Intersections to TOC by @tmkn in https://github.com/colinhacks/zod/pull/1450
- [#1468] Fix zod.dev main page cross origin links. by @agrahamg in https://github.com/colinhacks/zod/pull/1469
- Updates remix-domains library name and description in README by @diogob in https://github.com/colinhacks/zod/pull/1501
- Removed BRAND from ZodBrand Input definition by @Xetera in https://github.com/colinhacks/zod/pull/1492
- Add Zodix to readme ecosystem section by @rileytomasek in https://github.com/colinhacks/zod/pull/1506
- Fix small typos in README by @Yhozen in https://github.com/colinhacks/zod/pull/1521
- fix typo by @oasido in https://github.com/colinhacks/zod/pull/1528
- add
fataltoZodIssue. by @igalklebanov in https://github.com/colinhacks/zod/pull/1555 - Fix typo in ERROR_HANDLING.md by @Tsuyoshi84 in https://github.com/colinhacks/zod/pull/1543
- add
.finite()@ZodNumber. by @igalklebanov in https://github.com/colinhacks/zod/pull/1546 - Fix typing bug hiding errors of nullable composite fields by @tadeokondrak in https://github.com/colinhacks/zod/pull/1545
- #1227 Feature default on mismatch by @seancrowe in https://github.com/colinhacks/zod/pull/1537
- fix #1046
.required()doesn't remove optional flag from the result of.nullish(). by @igalklebanov in https://github.com/colinhacks/zod/pull/1542 - add
datetime()string formats by @samchungy in https://github.com/colinhacks/zod/pull/1494 - Bump minimatch from 3.0.4 to 3.1.2 by @dependabot in https://github.com/colinhacks/zod/pull/1558
- Bump minimist from 1.2.5 to 1.2.7 by @dependabot in https://github.com/colinhacks/zod/pull/1507
- #1171 support for refine, superRefine, transform and lazy in discriminatedUnion by @roblabat in https://github.com/colinhacks/zod/pull/1290
- branded type as normal argument by @KATT in https://github.com/colinhacks/zod/pull/1502
- Take
pathparameter into account within.parseAsync()by @RobinTail in https://github.com/colinhacks/zod/pull/1513 - Update README.md by @rosnerdev in https://github.com/colinhacks/zod/pull/1463
- Add
ZodSymbolby @santosmarco-caribou in https://github.com/colinhacks/zod/pull/1448 - Fix Minor Typos by @WebDevSimplified in https://github.com/colinhacks/zod/pull/1624
New Contributors
- @SrBrahma made their first contribution in https://github.com/colinhacks/zod/pull/1315
- @tmkn made their first contribution in https://github.com/colinhacks/zod/pull/1450
- @agrahamg made their first contribution in https://github.com/colinhacks/zod/pull/1469
- @diogob made their first contribution in https://github.com/colinhacks/zod/pull/1501
- @Xetera made their first contribution in https://github.com/colinhacks/zod/pull/1492
- @rileytomasek made their first contribution in https://github.com/colinhacks/zod/pull/1506
- @Yhozen made their first contribution in https://github.com/colinhacks/zod/pull/1521
- @oasido made their first contribution in https://github.com/colinhacks/zod/pull/1528
- @igalklebanov made their first contribution in https://github.com/colinhacks/zod/pull/1555
- @Tsuyoshi84 made their first contribution in https://github.com/colinhacks/zod/pull/1543
- @tadeokondrak made their first contribution in https://github.com/colinhacks/zod/pull/1545
- @seancrowe made their first contribution in https://github.com/colinhacks/zod/pull/1537
- @samchungy made their first contribution in https://github.com/colinhacks/zod/pull/1494
- @roblabat made their first contribution in https://github.com/colinhacks/zod/pull/1290
- @KATT made their first contribution in https://github.com/colinhacks/zod/pull/1502
- @RobinTail made their first contribution in https://github.com/colinhacks/zod/pull/1513
- @rosnerdev made their first contribution in https://github.com/colinhacks/zod/pull/1463
- @santosmarco-caribou made their first contribution in https://github.com/colinhacks/zod/pull/1448
- @WebDevSimplified made their first contribution in https://github.com/colinhacks/zod/pull/1624
Full Changelog: https://github.com/colinhacks/zod/compare/v3.19.1...v3.20.0
Commits:
- d04b303f9b616080c56dae25199bdd5cf2803f20 Update stale
- e933143738814fef53bb8e0813f9c54cb9079614 Fix typo in readme (#1385)
- 6011b675d07ce8de45557c5088fa27e1eeedf12b Update readme
- 033088da56a52b254fe3982d0d7fbcfec2a3bdcc Optimize object strip case (#1393)
- d40a5ebf28aa7735ac6d71d819b5fdc15d976f1d Fix refine with type guard signature (#1404)
- 2893e1659875944198aff28a3ba404858f834ed8 Make unknown input type for preprocess
- 3b75ae584e31d8bd06f7298247cd3d27520cf881 3.19.1
Features
Commits:
- 9066b9e6736b7f7669d867b405fdd3b4db16ff91 docs: fix links to anatine plugins in README (#1363)
- 0a2c9ab192a705528c64a6fe6f819eccf18ab37c docs: Update readme keyof typo (#1330)
- af086b6b571e4b5ae27b7ac105da8446d9e80a97 Update readme
- e75f348da1b26c7ae4a1075692f845cf74b620fd Add brand to toc
- f1dfabb6e16d769740c7e2458b8730b938d7b5b0 3.19.0 (#1383)
Commits:
- b3e623eafa5f4011675afce33e21d244dd25e775 docs: add zodios to zod ecosystem (#1283)
- 6fe152f98a434a087c0f1ecbce5c52427bd816d3 Added Avana Wallet as sponsor (#1281)
- d041b76b262f9f5f32cd0b78eea8f6a5d09fb691 docs: add link to runtyping (#1305)
- f923706e11199e054f213dc6d114cb987a1dd15e Refactor type checks (#1280)
- 814c1ebd8f1400820741101efde8329e2c9f375d docs: fix link to z.preprocess in Supporting date strings (#1319)
- 88e94efa219d7b911f929775b868c76cbb56d9d7 docs: fix link to Node/npm (#1312)
- 7c113ab22686047e4fa60c9a2c4cd882d0158a20 Add branded types (#1279)
- 59768246aa57133184b2cf3f7c2a1ba5c3ab08c3 3.18 (#1323)
Commits:
- d9c3637e1338583768922fb8535c163fa046c9c2 fix typo after ac2fb4a (#1267)
- 4ade47a391066b018c9f1c0712caab7783d7ceec Fix transform example (#1276)
- b29cee1cb72f46d38c619a724804c153a97d5937 Fix endsWith default message (#1273)
- a19acb8f90226cfa6036672385479af5874ba975 3.17.10
Commits:
- 1d16205a84c90ee2f0903e171e40b53c5da906cf feat(enum): return enum from object keys (#1216)
- 8b9daba5901d0f2d59b990696acec54b15701590 Don't use invalid_type_error for
undefinedfields. (#1175) - 0348e9b061e5b0dbbe06779c843b37d98da57e9c Fixed typing mistake in README.md (#1160)
- 15aa4ab279e0acb9fa103b3c0354b582991a36b3 Convert "an nullable" to "a nullable" (#1162)
- 55d2744205aa5cf71f6dcc91fc8d7c99d8c6bda7 3.17.9
Commits:
- dcc1483c063ccc0ab9061fe7bfcf296be81d8410 Add deno release workflow
- ac2fb4aa85f43d618ea881590ad6982626148935 Added native support for min and max date validations (#1222)
- e0ea1f6208e74101e19d0f900106dfc3ecf19450 Fix deno release workflow
- 121a2e21465f39ff5bb5f3d72bf76b6d907e1da8 3.17.8
Commits:
- a59c38452ed970e129ee9057c4e6d003d4d017bb Fix inferred function types
Commits:
- f73eabca9008a9ab87c8a30c5d506d8e092768d2 Add
zod-xlsxto the ecosystem section in README (#1203) - cbfe7044d84c42a23822549515ee51b112c35577 Add bigint support for literals (#1242)
Commits:
- 63f48194a6524aea59d711c02d6606a5d982d1fc Allow empty commits
- ff43b2ed0f783158bd12fb86d9fc04d26c625d1b Allow empty commit
- 799fbb17e20f7a3566348b9cafacd6999519e88e Add string.startsWith and string.endsWith (#1235)
- d9b8550c0815ed4e0137650bdc7358613358b88f 3.17.5
What's Changed
- Add seasoned to sponsors by @colinhacks in https://github.com/colinhacks/zod/pull/1167
- Update README for z.record key type schema by @gtarsia in https://github.com/colinhacks/zod/pull/1168
- Fix minor spelling and grammar issues in README by @remnantkevin in https://github.com/colinhacks/zod/pull/1202
- Fix link to node in readme by @BryanAbate in https://github.com/colinhacks/zod/pull/1255
- Update README to use headings for validation library names by @georgeblahblah in https://github.com/colinhacks/zod/pull/1250
- ZodString.minLength defaults to null to be consistent with maxLength by @Balastrong in https://github.com/colinhacks/zod/pull/1248
- Adds remix-domains to the README under Ecosystem by @gustavoguichard in https://github.com/colinhacks/zod/pull/1236
New Contributors
- @gtarsia made their first contribution in https://github.com/colinhacks/zod/pull/1168
- @remnantkevin made their first contribution in https://github.com/colinhacks/zod/pull/1202
- @BryanAbate made their first contribution in https://github.com/colinhacks/zod/pull/1255
- @georgeblahblah made their first contribution in https://github.com/colinhacks/zod/pull/1250
- @Balastrong made their first contribution in https://github.com/colinhacks/zod/pull/1248
- @gustavoguichard made their first contribution in https://github.com/colinhacks/zod/pull/1236
Full Changelog: https://github.com/colinhacks/zod/compare/v3.17.3...v3.17.4
Commits:
- 847cedf10d633cd420fbc29243894b1f846cc54f Remove type only imports
- b899edfbaffb2c5086d4da2e51c63416127723b4 Fix types
Commits:
- 44916fe7dee9413216ee0b24001cfbf835cda584 Remove circular dependency
- 0b4bc1df81f2be0c95c32da64cb370913f9cb15d Fix picking nonexistent keys
Commits:
- 4459e75b8e04bcddb06c2a4a3953a4599dcfc4bc feat: trim method for ZodString (#681)
- ff5de24f191a5df5275fdb0bb2ff24016fef38f3 Added README for deno (#1157)
- 4284011227b586045707814f0084b9447f28bfab Add error parameters to createZodEnum
- cb5db0fdbe5ec4e40dbc7cbe20506fafa87300fd 3.17.0
What's Changed
- Added README for deno by @omar-dulaimi in https://github.com/colinhacks/zod/pull/1157
- feat: trim method for ZodString by @Djaler in https://github.com/colinhacks/zod/pull/681
New Contributors
- @Djaler made their first contribution in https://github.com/colinhacks/zod/pull/681
Full Changelog: https://github.com/colinhacks/zod/compare/v3.16.1...v3.17.0
Commits:
- 3aedba54d7b0f4ba1f5cfca49a1744807dd33c81 Update docs
- a944dd7bd4043d6d9841217237e5208ee9098837 COnfigure docsify
- 0e5acd4d838cb7ed2e8445b9eb90510ab89fa523 Flatten schema docs
- 26d234d3f5976ab67ffd0bfbd89f55488534dd5c Clean up docs
- 7a37dac901d92f76e36c4f17e98bb582d2a55141 Tweak styling
- 1b7b529f66b5f899f88fa433bbafa103fee9f448 Fix table of contents styling
- 6bf9ea7ab0752f2f76d5831ac04f2588636abac6 Fix toc
- 4628c352565df06f0733a9f273c557dd78af34b3 Improve styling
- 4fcdbe7a56b7cd43134b1eda7f22dd9e95566cee Remove hash router
- 811da4ca25b12a981c3a93e3adb56fc669458ce3 Add metadata
- 625721dd7aaf1379946229db922aa1ccc21c8722 Add favicons
- 0367cdc7b0fbe9391343f0f64c0a0493206f9d2b Add oneliner
- 7ba4f67d4a85e8bf1bb97f39e9b07316e9f7d6a3 Add oneliner
- d362b93020c895386e7a1420dd6d57dfb4cce494 Add oneliner
- 4c9cbc67f31e18721874bb22fbafdcee38da58cf Add oneliner
- bef915308362ef499cb5b487f6ecf69454640167 Remove local assets
- 3ca7cff6e2f15af0ff4d2f8c2c09bc8bc3e1a622 Improve lighthouse scores
- b3ccd4c776e07820955d63d5f2bb771cf59d9c30 Fix docs
- ee40cb86f953f17704f1317dd1cddc92f0270d7c doc: fix link (#1130)
- d8d3806738fac67876b4ff9478b8f7a09ea6bc4a Add docs link (#1133)
- 401c4c4cfa954c31bd7182686bbeabe91694a877 Update index.html
- 7d1de148669daf21cbd896eef84a1b10ed052c08 Fix preload
- d506b083d4a7b2e5600317bd44ca1dba97709fe8 Fix syntax highlighting
- 347332c30b801c608ea29c89f61f0247a953bb83 Improve JSDoc deprecation warning for nonempty (#1152)
- 78369001b90ec3c23a9e12cbf0f24c9b9162d691 Instanceof issue fatal (#1131)
- b57a25c74d42d7a7f8e7b27ba727f331b8621d86 mod an example that is not correct (#1134)
- 51e93e7dd30b161d55e2f17d0907ecdd2f526c60 Added test for enums with defaults (#1149)
- 12214aad9b53f1f7965d3faa9e1e4b2f762cf006 Add Test for Union Recursive Type (#1148)
- 65d8f4ffb3099319e88e9406c062da8568bf6a3a 3.16.1
Commits:
- cb2b86c3d7c3f1c6fd3c503543f3e3668df7bad5 Update README.md (#1125)
- b7263281ce34f8d2859b348023b52e888283c5eb Add
nestjs-graphql-zodto ecosystem links (#1126) - ab8a37191fa2bde0e9bf32cf8184c19a19664c39 Fix ctx.addIssue in transform to work correctly with parseAsync (#1129)
- da0a42fafa159b47fc31cacfdadba9d50f2ebd16 Update ZodError.ts (#1127)
- c4740a6adfc874c35ac29cbff0d7a6bab2867e88 Restore existing type inference behaviour of z.ZodObject (#1122)
- c5366941f50d082cab33f7de5a945b5103e50927 Added expected and received properties to enum and native enum (#1123)
- 8f9ad5b602b0b336df7dcb5994689a38ab6261fe Update type signature for ZodInvalidEnumValueIssue
- 27121fdaa4697aafaae180439bd3708dd2c96c11 3.16
Commits:
- f814ef21ec3e701ea1cdaefdc69dfb59e8ad62d1 Improve docs
- c190a84bfe552c3804c0e0e04447b53257194de5 Clean up type signature of ZodFormattedError
Commits:
- d54ba359eda7e74f7373e612153e8e408904b14a feat: allow ctx.addIssue from transform (#1056)
- 36f4e88abc92e9513dbdf8d68899a2c3ff127c48 3.15.0
Commits:
- 21aab2a4b04428d7afe6255e78271db0617d6e61 fix(readme): Use Correct Test Link
- 753f627504a6801d3637a33efab6ad87b216d4a6 Merge pull request #1054 from FlorianWendelborn/patch-1
- a6e13ccf9f5656e386bef63e13db3561b692aec9 Remove hanging string expressions (#1073)
- c7792de989d47ac21872708f7188dc4e6143b172 Add UMD build (#1067)
- f11ba8fda8aac60abf22d292d9b4f936b9465c7b Standardize ZodError type helpers. Document ZodError.format(). Add mapper support to .format()
- 5ea9f8731f3ef8f244fd37e06a6fde9e7033ff34 Add Astro (#1076)
- 5ba2cc34ea39865837a9b06f46859849f89b3ce6 Update sponsors (#1081)
- cdca0db75a10525eca08696e8a44186cbe20c32a docs: infer
Literalfrom the schema in JSON type example (#1083) - f6981f867dc823ca01a09e8399074beff877b38b Small typo in readme (contraining => constraining) (#1096)
- 7296aae7d5062f60ca73d39adf71a2e62cc3d1d2 Add zod-to-openapi to Ecosystem in the Readme (#1109)
- 4cf7e7c5cba2ebe36db9d8f75f7866cb4a80bfc4 docs: fix typo on the error handling guide (#1111)
- fa4eebba089badc7590c6ad7dc3a60c252702282 Improve IDE integration for inferred object properties to support Go To Definition, Rename Symbol, etc. (#1117)
Commits:
- 823dda93193ab23f07b7e4625e54b1e8528cc530 Add invalid_literal issue
- d109f67187d66079dc2f3e7ff3fcb416e3d298c4 Merge pull request #1052 from colinhacks/literal-error
- 222df661cabe6ce7777ed4f2ba0640f9460edf08 Fully remove typeCache
- 22d418c2b0d7534561180eb0de6cf3107dcf85c5 Fully remove typeCache
- 0acd6f64d0dc346b23d9fcc67c8646be88dc8b54 Merge pull request #1058 from tmcw/fully-remove-typecache
- 024257cf171f7432e106da0672c7c8b6cb612f29 Faster extra keys detection
- 157f8c560a551b65148aed0b419513993badfb82 Merge pull request #1057 from tmcw/faster-extra-keys
- 819fb499ee4ed663a266c19ee541024b30c34ed2 3.14.4
Commits:
- 66f044b5c3fb2a21df6c8a854fb212852ce0aad9 Improve precommit hooks
- 60acdc0f1aca48dcd67590daeab61317c4a92fab Fix prepublish
- 361c789d84a28fb0c243008f21c23f240049c2a6 Test husky
- 2348c00719ac5f139a8da1a84c2793017d11b863 Test husky
- 0dbd4ec8154d3390e23bdd2b1238fd20276893bf Test husky
- ac187fa1218ae8bdf2664f7d8457e04cff4b0816 Reformat
- 4fb3a2967d1830633dc227e4da394cde5a87b234 Add files
- b6006f37d6a2ac879c80d703a45386d573ed1f5c Merge pull request #1034 from colinhacks/husky
- 35a74f5147e5ea400a17cbeb3926ec81eac414b7 Remove coverage badge generation, fix release CI
- 1974cfbc8ef98f162a9dabf5eb333eb475ca7eac Add codecov
- 4bd66a42c143070063a5e3fccfde2d7615c1433b Remove coverage
- 6173d5cbcc6b6b9f0152ae0a783097affdf2edf6 Merge pull request #1035 from colinhacks/coverage
- 0780ee3630a2b7d0e29573edbfd0ae7bf0b8e345 Fix CI badge
- f59df396529055404eca5300d12e1765bb157c65 Faster paths
- 3662eb28daed63ccaf73ee00758dd13de2810bcd Update src/types.ts
- 2ffcd8d6ebd69036c483c18135008f85db4b78e7 Update ZodMap for new ParseInputLazyPath structure
- 0ad9e128eb35bac7d715b6aec24bb8b55e3b3700 Merge pull request #1036 from tmcw/fast-path2
- d8628e19dafdeb336bec924692dc6c7a67775aba Add fastify-type-provider-zod
- 1713b0aaceb952d298d931d8d507a49e6e12fab5 Add Supervillain to Ecosystem section
- f3db86704a02d3ae075ef976018f21cb8b27641e Merge pull request #1047 from Southclaws/patch-1
- 2ccce0704f1b572ed85b15d225c39a65057e1580 Add generic functions guide to README
- baf9b533bd367910819f660d195dd5831c03ca69 Add default for first argument of ZodType
Commits:
- 76d2fe0b321e8211d470b7d340780218e6fab941 Faster optional & nullable values
- 38cc89d649c919e6696b2d246061b9114fb00307 Merge pull request #1028 from tmcw/faster-optionals
- 900490457640cb68ffeda0d61fe7550bf245f569 Implement release CI
- 5d356ddbb7c859334ff17eb78b220bbf5470b407 Remove logs in build.mjs
- 25b41e6124518d728bde98a9bc7fba71815c474a Dry-run: false
- 6a703d8616cae1f43008e91d7385c8398454aa40 Rename workflows
- 0a5f644437323765216b8f5056967c667637b1cb Update release, remove fix.yml
- 01ca1164df331bc8aeb200cf8f664f66c103c05d Generate Deno before testing
- 25bab35735dc27d72b1c7137c1b29d9e48626234 Update script names
- cc458a0c4382e81de3f451df0393fccc9add10dd Prevent duplicate jobs
- a3e3d4551c4a99a571e06b8c073fa28153b66da3 Prevent duplicate jobs
- b5a93f2348a8e7243263dcb7dc09646f2267eeaa Fix prettier command
- 3a27c0cf4384742d149efe4e9cc1a7ee8dd9a948 Upgrade eslint version
- cadfa20a0ddcc7277735babc62be41a1f82f9554 Fix job id
- 863346b158ce89a937221a677758423dcd207488 chore: Format, lint, build Deno
- e02a9cae1b55d4b0fa0a6d87ea768381f5084081 Remove dryrun
- db4c8bf5f66e186b4496b0c00b2b067c4cf1abc2 Add deno
- 88d12399e098c81d91820c34b36dc049f0202a32 Update release
- 1a4a1c2eeca86743ce9f3071e69e712b56304ee5 Merge pull request #1030 from colinhacks/ci
- 43b258b6bb3c4dfcad59fe58afaac2f730217dbb chore: Format, lint, build Deno
What's Changed
- Reduce memory churn, avoid generating ctx when not necessary, much faster valid primitives by @tmcw in https://github.com/colinhacks/zod/pull/1025
Full Changelog: https://github.com/colinhacks/zod/compare/v3.14.0...v3.14.1
What's Changed
- Add realworld benchmark by @tmcw in https://github.com/colinhacks/zod/pull/1024
- Remove unnecessary docs files by @Shreyas-SAS in https://github.com/colinhacks/zod/pull/1013
- Add ZodDiscriminatedUnion to ZodFirstPartySchemaTypes by @jacobmischka in https://github.com/colinhacks/zod/pull/1002
- Remove typeCache by @tmcw in https://github.com/colinhacks/zod/pull/1023
- Performance - target es2018 by @tmcw in https://github.com/colinhacks/zod/pull/1022
- Fix ERROR_HANDLING.md typo by @susiyaki in https://github.com/colinhacks/zod/pull/1027
- Fast unions by @tmcw in https://github.com/colinhacks/zod/pull/1026
New Contributors
- @tmcw made their first contribution in https://github.com/colinhacks/zod/pull/1024
- @Shreyas-SAS made their first contribution in https://github.com/colinhacks/zod/pull/1013
- @esamattis made their first contribution in https://github.com/colinhacks/zod/pull/1003
- @jacobmischka made their first contribution in https://github.com/colinhacks/zod/pull/1002
- @susiyaki made their first contribution in https://github.com/colinhacks/zod/pull/1027
Full Changelog: https://github.com/colinhacks/zod/compare/v3.13.4...v3.14.0
What's Changed
- Removing source maps and uglification of ES modules
- exporting ZodDiscriminatedUnionOption by @JacobWeisenburger in https://github.com/colinhacks/zod/pull/987
- Add
typesfield toexportsinpackage.jsonby @shroudedcode in https://github.com/colinhacks/zod/pull/906 - NaN type by @noyan-alimov in https://github.com/colinhacks/zod/pull/898
- Add Contributor's Convenant as Code of Conduct by @scotttrinh in https://github.com/colinhacks/zod/pull/912
- Records should be partial so we're not required to use all keys by @jeremybull in https://github.com/colinhacks/zod/pull/752
New Contributors
- @shroudedcode made their first contribution in https://github.com/colinhacks/zod/pull/906
- @noyan-alimov made their first contribution in https://github.com/colinhacks/zod/pull/898
- @jeremybull made their first contribution in https://github.com/colinhacks/zod/pull/752
Full Changelog: https://github.com/colinhacks/zod/compare/v3.12.0...v3.13.2
- Fix documentation for ZodArray .element (issue #744) by @maxmvsk in https://github.com/colinhacks/zod/pull/745
- Added json-schema-to-zod to ecosystem by @StefanTerdell in https://github.com/colinhacks/zod/pull/756
- chore: add soly package to ecosystem by @mdbetancourt in https://github.com/colinhacks/zod/pull/811
- Update README.md by @JacobWeisenburger in https://github.com/colinhacks/zod/pull/795
- Fix typing typo in documentation by @pspeter3 in https://github.com/colinhacks/zod/pull/818
- Fix typo in Sets section of README by @jwr12135 in https://github.com/colinhacks/zod/pull/793
- add zod-to-ts to ecosystem by @sachinraja in https://github.com/colinhacks/zod/pull/824
- Fix grammar mistake in README for "Cyclical objects" by @Nilstrieb in https://github.com/colinhacks/zod/pull/825
- Fix broken twitter link by @ajcwebdev in https://github.com/colinhacks/zod/pull/827
- Fix instanceof map and set by @NumminorihSF in https://github.com/colinhacks/zod/pull/840
- Further translate untranslated English parts by @geenva in https://github.com/colinhacks/zod/pull/837
- Fix mistake in example (README_ZH.md) by @astef in https://github.com/colinhacks/zod/pull/836
- Fix mistake in example (README.md) by @astef in https://github.com/colinhacks/zod/pull/835
- Add Readonly to ZodUnionOptions by @cefn in https://github.com/colinhacks/zod/pull/832
- Add min(), max(), size() and nonempty() to ZodSet schema by @whitebyte in https://github.com/colinhacks/zod/pull/823
- README grammarz by @cedric-h in https://github.com/colinhacks/zod/pull/819
- Don't include received value in enum/literal error messages (fixes #461) by @pasieronen in https://github.com/colinhacks/zod/pull/777
- fix: Add
descriptiontoProcessedCreateParamsby @equt in https://github.com/colinhacks/zod/pull/767 - fix: intersection with date fields by @dirgapeter in https://github.com/colinhacks/zod/pull/773
- Remove duplicated block on custom error messages by @5minpause in https://github.com/colinhacks/zod/pull/758
- Add types to extract error results from schema by @fnky in https://github.com/colinhacks/zod/pull/856
- change UUID regex to support different UUID variants by @narrowei in https://github.com/colinhacks/zod/pull/860
- added graphql-codegen-typescript-validation-schema (README.md) by @Code-Hex in https://github.com/colinhacks/zod/pull/902
- Discriminated union by @alexxander in https://github.com/colinhacks/zod/pull/899
- README consistency fixes by @JacobWeisenburger in https://github.com/colinhacks/zod/pull/876
- added z.date documentation to README.md. fixes #880 by @JacobWeisenburger in https://github.com/colinhacks/zod/pull/881
- Add zod-prisma to the ecosystem section by @ahhshm in https://github.com/colinhacks/zod/pull/939
- Add badges and call to action to README by @konhi in https://github.com/colinhacks/zod/pull/947
- Remove duplicated
processCreateParamsinZodNumberby @equt in https://github.com/colinhacks/zod/pull/766
Support type guards as refinements #727 Fix #732
Support TypeScript 4.5.
New parsing engine. Zod now surfaces more errors.
v3.9.8
✨ Zod 3.9 ✨
Custom error messages in schemas
const name = z.string({
invalid_type_error: "Name must be string",
required_error: "Name is required",
});
Under the hood, this creates a custom error map that's bound to the schema. You can also pass a custom error map explicitly.
const name = z.string({ errorMap: myErrorMap });
Rest parameters for tuples
const myTuple = z.tuple([z.string(), z.number()]).rest(z.boolean());
type t1 = z.output<typeof myTuple>; // [string, number, ...boolean[]]
Selective .partial
You can specify certain fields to make optional with the ZodObject.partial method.
const user = z.object({
name: z.string(),
age: z.number(),
});
const optionalNameUser = user.partial({ name: true });
// { name?: string; age: number; }
Support key schema in ZodRecord
Previously, z.record only accepted a single schema:
z.record(z.boolean()); // Record<string, boolean>;
Now z.record has been overloaded to support two schemas. The first validates the keys of the record, and the second validates the values.
const schema = z.record(z.number(), z.boolean());
type schema = z.infer<typeof schema>; // Record<number, boolean>
const schema = z.record(z.enum(["Tuna", "Trout"]), z.boolean());
type schema = z.infer<typeof schema>; // Record<"Tuna" | "Trout", boolean>
Don't short-circuit on some validation errors
Certain issue types "short circuit" the rest of the validation logic. If you pass a number into a ZodString schema, Zod throws an error immediately, without passing the input through any downstream refinements or transforms. This is intentional; those refinements/transforms are likely to throw unexpected errors since they assume a number input.
However other kinds of errors shouldn't "short circuit" like this. For instance z.string().min(10).email(). If we try to parse "asdf" with this schema, we should get two errors: "Invalid email" and "Input should contain at least 10 characters". If we short circuit after the "min" error, then Zod fails to surface the full set of validation issues.
Zod now considers certain classes of validation errors "continuable", in that they don't short circuit validation logic. This makes Zod more usable in form validation settings like this:
const user = z
.object({
password: z.string().min(6),
confirm: z.string(),
})
.refine((data) => data.password === data.confirm, "Passwords don't match");
const result = user.safeParse({ password: "asdf", confirm: "qwer" });
This will return an error with two issues. Previously the parsing would have short-circuited after the inner password was invalid.
/*
ZodError: [
{
"code": "too_small",
"minimum": 6,
"type": "string",
"inclusive": true,
"message": "Should be at least 6 characters",
"path": [ "password" ]
},
{
"code": "custom",
"message": "Passwords don't match",
"path": [ "confirm" ]
}
]
*/
Release: zod@3.8.0
What's new:
z.preprocess
This lets you transform input data before it is parsed by your schema. This is useful for several use cases, notably type coercion. Usage:
const coercedString = z.preprocess(
val => String(val),
z.string()
)
mySchema.parse(12); // => "12"
mySchema.parse(true); // => "true"
CUID validation
Courtesy of @alii
const cuid = z.string().cuid()
cuid.parse("ckopqwooh000001la8mbi2im9");
Improved .deepPartial()
The .deepPartial() method on object schemas now recursively traverses through ZodArray, ZodTuple, ZodOptional, and ZodNullable elements. Previously, this method only worked in hierarchies of simple object schemas.
const mySchema = z.object({
name: z.string(),
array: z.array(z.object({ asdf: z.string() })),
tuple: z.tuple([
z.object({ value: z.string() })
]),
})
const partialed = mySchema.deepPartial();
type partialed = z.infer<typeof partialed>;
/*
{
name?: string | undefined;
array?: {
asdf?: string | undefined;
}[] | undefined;
tuple?: [{value?: string}] | undefined;
}
*/
Improve Zod stack traces
- Eliminate
ZodNonEmptyArray, addCardinalitytoZodArray - Add optional error message to
ZodArray.nonempty - Add
.gt/.gte/.lt/.ltetoZodNumber, aliasmin -> gteandmax -> lte
-
Add IE11 support
-
ZodError.flattennow optionally accepts a map function for customizing the output -
.void()now only accepts undefined, not null. -
z.enumnow supportsReadonlystring tuplesconst HTTP_SUCCESS = ["200", "201"] as const; const arg = z.enum(HTTP_SUCCESS);
3.5
- Add discriminator to all first-party schema defs
Bug fixes.
3.4
unknownandanyschemas are always interpreted as optional. Reverts change from 3.3.
3.3.0
- HUGE speed improvements
- Added benchmarking:
yarn benchmark - Type signature of
ZodType#_parsehas changed. This will affects users who have implemented custom subclasses ofZodType. - [reverted] Object fields of type
unknownare no longer inferred as optional.
Refactor ZodString and ZodNumber validations internally: #469
Stable v3 release! 🚀🚀🚀
Major improvement to object schemas.
Implemented .pick, .omit, and .augment. Documented in README.
Implemented ZodRecord.
Usage:
const myRecord = z.record(z.object({ name: z.string() }));
type myRecord = z.TypeOf<typeof myRecord>
// => { [k: string]: { name: string } }
myRecord.parse({
asdf: { name: 'Bruce' },
1234: { name: 'Barry' },
}) // passes
myRecord.parse({
id1: true
}) // TypeError
myRecord.parse({
id1: true
} as any) // throws