Glean 拾遗
Daily /2026-09-02 / Zod 4.5: z.compile() precompilation speeds parse up to 9x, slashes memory

Zod 4.5: z.compile() precompilation speeds parse up to 9x, slashes memory

Source zod.dev Glean’d 2026-09-02 06:00 Read 26 min
AI summary

Zod 4.5 introduces z.compile(), an AOT schema compiler that speeds up parsing of objects, arrays, and unions by ~3–9x. Combined with z.validate()—a fast boolean check that skips ZodError construction—invalid inputs are up to 16x cheaper to reject than safeParse. Benchmarks show 47.5M ops/s on the Moltar parseSafe fixture, ahead of typia's 45.3M. A move of bound methods to prototypes cuts per-schema heap retention by up to 9.8x. The release also includes breaking changes: string length now counts Unicode code points, z.iso.datetime() requires seconds, record keys and intersections match TypeScript semantics, and __proto__ is always stripped. Useful for TS teams doing heavy runtime validation in services, forms, and data pipelines.

Original · 26 min
zod.dev ↗
§ 1

Zod 4.5 is now available.

At a glance:

z.compile() — the flagship feature of Zod 4.5

z.creditCard() — 12–19 digits plus Luhn checksum

z.properties() — the multi-property counterpart to z.property()

z.deepPartial()/.exactPartial()

z.validate(): boolean — a fast-path to verify input validity without a full parse (up to 16x faster on invalid data)

9x reduction in memory footprint

New locales: Bengali (bn), Central Kurdish (ckb), Hindi (hi), Kannada (kn), Norwegian Nynorsk (nn), Brazilian Portuguese (pt-BR), Slovak (sk), Turkmen (tk)

Zod 4.5 正式发布。

速览:

z.compile()——Zod 4.5 的旗舰特性

z.creditCard()——12–19 位数字,附 Luhn 校验

z.properties()——与 z.property() 对应的多属性版本

z.deepPartial()/.exactPartial()

z.validate(): boolean——无需完整 parse 即可校验输入是否合法的快速路径,无效数据上最快可提升 16 倍

内存占用降低 9 倍

新语言:孟加拉语 (bn)、中库尔德语 (ckb)、印地语 (hi)、卡纳达语 (kn)、新挪威语 (nn)、巴西葡萄牙语 (pt-BR)、斯洛伐克语 (sk)、土库曼语 (tk)

§ 2

You can now pre-compile any Zod schema using z.compile(schema). This dramatically speeds up parsing performance.

A compiled schema can be used exactly like an uncompiled one. There are no special rules around compiled schemas. They're just faster.

On objects, arrays, and unions, this speeds up parsing by a factor of ~3–9. More complex schemas stand to benefit more than simpler ones.

Time per parse on a shared nanosecond axis, standard parser as a gray bar with the compiled time as a blue bar inside it: an array of 10 objects 377 ns to 68 ns (5.5x), a 20-key object 301 ns to 38 ns (7.8x), an array of 10 strings 241 ns to 33 ns (7.3x), a union of 3 objects 190 ns to 36 ns (5.3x), a 3-element tuple 119 ns to 33 ns (3.6x), a 5-key strict object 117 ns to 32 ns (3.7x), a discriminated union 92 ns to 27 ns (3.4x), a 5-key object 76 ns to 28 ns (2.8x); up to 7.8x faster when compiled

Time per parse on a shared nanosecond axis, standard parser as a gray bar with the compiled time as a blue bar inside it: an array of 10 objects 377 ns to 68 ns (5.5x), a 20-key object 301 ns to 38 ns (7.8x), an array of 10 strings 241 ns to 33 ns (7.3x), a union of 3 objects 190 ns to 36 ns (5.3x), a 3-element tuple 119 ns to 33 ns (3.6x), a 5-key strict object 117 ns to 32 ns (3.7x), a discriminated union 92 ns to 27 ns (3.4x), a 5-key object 76 ns to 28 ns (2.8x); up to 7.8x faster when compiled

Time per parse by schema type, standard parser vs compiled — lower is better (benchmark)

现在可以用 z.compile(schema) 预编译任意 Zod schema,解析性能会大幅提升。

编译后的 schema 用法与未编译的完全相同,没有任何特殊规则——只是更快。

在对象、数组和联合类型上,解析速度约提升 3–9 倍;schema 越复杂,收益越明显。

Time per parse on a shared nanosecond axis, standard parser as a gray bar with the compiled time as a blue bar inside it: an array of 10 objects 377 ns to 68 ns (5.5x), a 20-key object 301 ns to 38 ns (7.8x), an array of 10 strings 241 ns to 33 ns (7.3x), a union of 3 objects 190 ns to 36 ns (5.3x), a 3-element tuple 119 ns to 33 ns (3.6x), a 5-key strict object 117 ns to 32 ns (3.7x), a discriminated union 92 ns to 27 ns (3.4x), a 5-key object 76 ns to 28 ns (2.8x); up to 7.8x faster when compiled

Time per parse on a shared nanosecond axis, standard parser as a gray bar with the compiled time as a blue bar inside it: an array of 10 objects 377 ns to 68 ns (5.5x), a 20-key object 301 ns to 38 ns (7.8x), an array of 10 strings 241 ns to 33 ns (7.3x), a union of 3 objects 190 ns to 36 ns (5.3x), a 3-element tuple 119 ns to 33 ns (3.6x), a 5-key strict object 117 ns to 32 ns (3.7x), a discriminated union 92 ns to 27 ns (3.4x), a 5-key object 76 ns to 28 ns (2.8x); up to 7.8x faster when compiled

按 schema 类型比较单次解析耗时,标准解析器对比编译后的版本——越低越好(基准)

§ 3

Below are the Moltar benchmark results comparing Zod (compiled and uncompiled) against the Moltar ParseSafe bench.

Bar chart of operations per second on the moltar benchmark fixture, parseSafe category: Zod 4 compiled 47.5M, typia 45.3M, Zod 4 11.6M, valibot 1.8M, effect 1.7M, Zod 3 1.2M, arktype 152k, yup 121k

Bar chart of operations per second on the moltar benchmark fixture, parseSafe category: Zod 4 compiled 47.5M, typia 45.3M, Zod 4 11.6M, valibot 1.8M, effect 1.7M, Zod 3 1.2M, arktype 152k, yup 121k

Throughput on the moltar benchmark fixture (parseSafe: returns a new object with unknown keys stripped) — higher is better (benchmark)

And the equivalent results for the Moltar AssertLoose bench. Tested against the new z.validate(schema, input) function (detailed later in the post).

Bar chart of operations per second on the moltar benchmark fixture, assertLoose category: typia 74.9M, arktype 66.2M, Zod 4 compiled 60.6M, Zod 4 6.5M, valibot 1.9M, effect 1.7M, Zod 3 1.2M, yup 124k

Bar chart of operations per second on the moltar benchmark fixture, assertLoose category: typia 74.9M, arktype 66.2M, Zod 4 compiled 60.6M, Zod 4 6.5M, valibot 1.9M, effect 1.7M, Zod 3 1.2M, yup 124k

Throughput on the moltar benchmark fixture (assertLoose: returns a boolean, unknown keys allowed) — higher is better (benchmark)

下面是用 Moltar 基准做的对比,Zod(编译版与未编译版)对 Moltar ParseSafe 基准。

Bar chart of operations per second on the moltar benchmark fixture, parseSafe category: Zod 4 compiled 47.5M, typia 45.3M, Zod 4 11.6M, valibot 1.8M, effect 1.7M, Zod 3 1.2M, arktype 152k, yup 121k

Bar chart of operations per second on the moltar benchmark fixture, parseSafe category: Zod 4 compiled 47.5M, typia 45.3M, Zod 4 11.6M, valibot 1.8M, effect 1.7M, Zod 3 1.2M, arktype 152k, yup 121k

Moltar 基准上的吞吐量(parseSafe:返回剔除未知键后的新对象)——越高越好(基准)

下面是 Moltar AssertLoose 基准的对应结果,测试对象是文中稍后详细介绍的新 z.validate(schema, input) 函数。

Bar chart of operations per second on the moltar benchmark fixture, assertLoose category: typia 74.9M, arktype 66.2M, Zod 4 compiled 60.6M, Zod 4 6.5M, valibot 1.9M, effect 1.7M, Zod 3 1.2M, yup 124k

Bar chart of operations per second on the moltar benchmark fixture, assertLoose category: typia 74.9M, arktype 66.2M, Zod 4 compiled 60.6M, Zod 4 6.5M, valibot 1.9M, effect 1.7M, Zod 3 1.2M, yup 124k

Moltar 基准上的吞吐量(assertLoose:返回布尔值,允许未知键)——越高越好(基准)

§ 4

Zod's entire test suite runs twice—once normally and again with auto-compilation enabled globally—to ensure perfect fidelity.

import "zod/compile"

To compile every schema in an application, import zod/compile once at the top of your entry point. Every schema constructed after that import is automatically compiled the first time it's used to parse data.

It also works as a Node.js CLI flag, which guarantees it runs before any module defines a schema:

Or set preload in bunfig.toml or nub.jsonc.

nub.jsonc

Zod 的完整测试套件会跑两遍:一遍常规运行,一遍全局开启自动编译,以确保两者行为完全一致。

import "zod/compile"

如果希望应用里每个 schema 都编译,只需在入口文件顶部引入一次 zod/compile。此后构造的每个 schema 都会在首次用于解析数据时自动编译。

该功能也支持 Node.js CLI 标志,可保证在任何模块定义 schema 之前生效:

或者也可以在 bunfig.toml 或 nub.jsonc 中设置 preload。

nub.jsonc

§ 5

A new string format: 12–19 digits, optionally separated by single spaces or hyphens, with a valid Luhn checksum. (#5931)

新增字符串格式:12–19 位数字,可选用单个空格或连字符分隔,并要求通过 Luhn 校验和。(#5931)

§ 6

The multi-property counterpart to z.property(). (#5912)

这是 z.property() 的多属性版本。(#5912)

§ 7

Back in functional form after being removed as a method in Zod 4. (#5928)

The result is still a ZodObject, so .shape and .extend() keep working.

Like .partial(), but wraps each field in z.exactOptional() instead of z.optional(): keys may be omitted, but an explicit undefined is rejected. This matches TypeScript's Partial<> under exactOptionalPropertyTypes. (#6065)

In Zod Mini it's a top-level function: z.exactPartial(Recipe).

在 Zod 4 中作为方法被移除后,如今以函数形式回归。(#5928)

结果仍是 ZodObject,所以 .shape 和 .extend() 继续可用。

与 .partial() 类似,但每个字段用 z.exactOptional() 而不是 z.optional() 包裹:键可以省略,但显式传入 undefined 会被拒绝。这与开启 exactOptionalPropertyTypes 时 TypeScript 的 Partial<> 行为一致。(#6065)

在 Zod Mini 中它是顶层函数:z.exactPartial(Recipe)。

§ 8

Standalone boolean validation, in Zod, Zod Mini, and Zod Core. It answers "is this input valid?" without constructing a ZodError, which makes rejection cheap: on invalid input it is up to 16x faster than .safeParse().success. The return type is a guard on the schema's input type, and z.validateAsync() covers schemas with async refinements. (#6471)

独立布尔校验,在 Zod、Zod Mini 与 Zod Core 中均可用。它回答“这个输入是否合法”,不会构造 ZodError,因此拒绝成本很低:对无效输入,比 .safeParse().success 快最多 16 倍。返回类型是该 schema 输入类型的类型守卫;z.validateAsync() 则覆盖带异步 refine 的 schema。(#6471)

§ 9

Project a schema onto its input or output side. Useful for validating the two halves of a codec independently. (#5928)

This is a no-op on schemas not containing codecs/pipes.

将 schema 投影到输入侧或输出侧,适合独立校验编解码器两端的值。(#5928)

对于不包含 codec/pipe 的 schema,这是一个空操作。

§ 10

A utility to define a Zod schema that agrees exactly with a static type, often one that is handwritten or externally defined. (#5913)

这个工具用来定义与某个静态类型完全一致的 Zod schema,常用于手写或外部定义的类型。(#5913)

§ 11

Extract a discriminated union member by discriminator value. (#5947)

按判别值从可判别联合中提取对应成员。(#5947)

§ 12

Zod recursive schemas now support cyclical data. For bundle size reasons, Zod Mini requires you to register a memoizer explicitly. (#6387, #6482)

Zod 的递归 schema 现在支持环形数据。出于包体积考虑,Zod Mini 需要你显式注册一个 memoizer。(#6387, #6482)

§ 13

In Zod 4.4 a bare z.string() retained 7.5kb of heap. In Zod 4.5 it retains 784 bytes.

Heap retained by one schema instance on a shared kilobyte axis, zod 4.4.3 as a gray bar with the 4.5 size as a blue bar inside it: a 10-key object 82.0kb to 11.0kb (7.4x), a union 17.5kb to 2.13kb (8.3x), z.string().min(1) 16.7kb to 3.37kb (5.0x), a record 16.4kb to 2.64kb (6.2x), z.string().optional() 12.6kb to 1.50kb (8.4x), an array of strings 11.2kb to 1.93kb (5.8x), z.string() 7.53kb to 784b (9.8x), z.number() 4.44kb to 706b (6.4x); up to 9.8x less memory than 4.4.3

Heap retained by one schema instance on a shared kilobyte axis, zod 4.4.3 as a gray bar with the 4.5 size as a blue bar inside it: a 10-key object 82.0kb to 11.0kb (7.4x), a union 17.5kb to 2.13kb (8.3x), z.string().min(1) 16.7kb to 3.37kb (5.0x), a record 16.4kb to 2.64kb (6.2x), z.string().optional() 12.6kb to 1.50kb (8.4x), an array of strings 11.2kb to 1.93kb (5.8x), z.string() 7.53kb to 784b (9.8x), z.number() 4.44kb to 706b (6.4x); up to 9.8x less memory than 4.4.3

Retained heap per schema instance, Zod 4.4.3 vs 4.5 (benchmark)

In Zod 4.4 and earlier, all schema methods were automatically bound to the instance itself. This allowed users to pluck methods from schemas without causing issues due to this-binding.

A consequence of this is that each bound method allocates space on the heap; method implementations are not shared across all instances via prototype, as you'd expect. Zod 4.5 implements a method memoization pattern that avoids allocating bound methods until they are actually accessed.

Zod 4.4 中一个裸 z.string() 会保留 7.5kb 堆内存;Zod 4.5 中只保留 784 字节。

Heap retained by one schema instance on a shared kilobyte axis, zod 4.4.3 as a gray bar with the 4.5 size as a blue bar inside it: a 10-key object 82.0kb to 11.0kb (7.4x), a union 17.5kb to 2.13kb (8.3x), z.string().min(1) 16.7kb to 3.37kb (5.0x), a record 16.4kb to 2.64kb (6.2x), z.string().optional() 12.6kb to 1.50kb (8.4x), an array of strings 11.2kb to 1.93kb (5.8x), z.string() 7.53kb to 784b (9.8x), z.number() 4.44kb to 706b (6.4x); up to 9.8x less memory than 4.4.3

Heap retained by one schema instance on a shared kilobyte axis, zod 4.4.3 as a gray bar with the 4.5 size as a blue bar inside it: a 10-key object 82.0kb to 11.0kb (7.4x), a union 17.5kb to 2.13kb (8.3x), z.string().min(1) 16.7kb to 3.37kb (5.0x), a record 16.4kb to 2.64kb (6.2x), z.string().optional() 12.6kb to 1.50kb (8.4x), an array of strings 11.2kb to 1.93kb (5.8x), z.string() 7.53kb to 784b (9.8x), z.number() 4.44kb to 706b (6.4x); up to 9.8x less memory than 4.4.3

各 schema 实例保留的堆内存对比,Zod 4.4.3 vs 4.5(基准)

在 Zod 4.4 及更早版本中,所有 schema 方法都会自动绑定到实例自身。这让用户可以把方法从 schema 上取出来用,而不用担心 this 绑定问题。

代价是每个绑定方法都会在堆上占用空间;方法实现不会像预期的那样通过 prototype 在所有实例间共享。Zod 4.5 采用了方法记忆化(memoization)模式,只在方法真正被访问时才分配绑定方法。

§ 14

Zod .parse()/.safeParse() instantiates a JavaScript Error, which captures a stack trace. In the case of validation failures, this is often much slower than the parsing logic itself. When using .safeParse(), Zod no longer captures this stack trace, speeding up failure-path parses by a factor of ~7.5x. (#6316, #6450)

Bar chart of time per failing safeParse: zod 4.4 at 6.3 microseconds, zod 4.5 at 840 nanoseconds — 7.6x faster

Bar chart of time per failing safeParse: zod 4.4 at 6.3 microseconds, zod 4.5 at 840 nanoseconds — 7.6x faster

Player schema (benchmark)

Zod 的 .parse()/.safeParse() 会实例化一个 JavaScript Error 来捕获堆栈。校验失败时,这通常比解析逻辑本身慢得多。现在使用 .safeParse() 时 Zod 不再捕获这个堆栈,失败路径的解析速度提升约 7.5 倍。(#6316, #6450)

Bar chart of time per failing safeParse: zod 4.4 at 6.3 microseconds, zod 4.5 at 840 nanoseconds — 7.6x faster

Bar chart of time per failing safeParse: zod 4.4 at 6.3 microseconds, zod 4.5 at 840 nanoseconds — 7.6x faster

Player schema(基准)

§ 15

A shape can now declare a symbol key. TypeScript tracks it: a const symbol infers as unique symbol, so z.infer makes the key required and checks its value type. Undeclared symbol keys are still ignored. (#6448)

shape 现在可以声明 symbol 键。TypeScript 会对其跟踪:const symbol 推断为 unique symbol,因此 z.infer 会把这个键设为必填,并检查其值类型。未声明的 symbol 键仍会被忽略。(#6448)

§ 16

⚠️ z.iso.datetime() requires seconds

RFC 3339 mandates seconds. z.iso.datetime() and z.iso.datetime({ offset: true }) no longer accept minute-precision input like 2020-01-01T06:15Z. local: true still admits 2020-01-01T06:15, since an unqualified datetime is outside RFC 3339 either way. (#6457)

To accept both forms, union the two precisions:

⚠️ z.iso.datetime() 现在必须包含秒

RFC 3339 规定必须有秒。z.iso.datetime() 和 z.iso.datetime({ offset: true }) 不再接受 2020-01-01T06:15Z 这种仅到分钟精度的输入。local: true 仍然接受 2020-01-01T06:15,因为不带时区的日期时间本来就不在 RFC 3339 范围内。(#6457)

若要同时接受两种形式,可以把两种精度 union 起来:

§ 17

⚠️ String length counts code points

.min(), .max(), and .length() counted UTF-16 code units, so z.string().max(5) rejected five emoji. They now count Unicode code points, which is what every non-JS consumer of a length bound does (Postgres, MySQL, Go, Python, and the maxLength that z.toJSONSchema() emits). .max() only loosens; .min() and .length() tighten for astral input. Graphemes are unchanged — a ZWJ sequence is still several code points. (#6441)

Closes #3355.

⚠️ 字符串长度现在按 Unicode 码点计算

此前 .min()、.max() 和 .length() 按 UTF-16 码元计数,所以 z.string().max(5) 会拒绝五个 emoji。现在它们按 Unicode 码点计数,这与所有非 JS 消费者对长度边界的处理一致(Postgres、MySQL、Go、Python,以及 z.toJSONSchema() 生成的 maxLength)。.max() 只会放宽;对星芒字符,.min() 和 .length() 会收紧。字形簇(grapheme)行为不变——ZWJ 序列仍然算多个码点。(#6441)

关闭 #3355。

§ 18

⚠️ Record keys and intersections match TypeScript

A record's key schema now governs only the keys that match it, the way TypeScript treats an index signature. Intersecting an object with a pattern-keyed record no longer rejects the object's own keys. (#6412)

Separately, an unrecognized_keys issue no longer aborts the schema it came from, so a strict object with an extra key and a bad value now reports both issues instead of just the first. Closes #2200, #2573, #4017, #5663.

⚠️ record 键与交叉类型现在与 TypeScript 行为一致

record 的键 schema 现在只约束匹配它的那些键,就像 TypeScript 处理索引签名一样。将对象与 pattern-keyed record 做交叉,不再拒绝对象自身的键。(#6412)

另外,unrecognized_keys 问题不再中止它来源的 schema,因此一个 strict 对象如果既有多余键又有错误值,现在会同时报告两个问题,而不是只报告第一个。关闭 #2200、#2573、#4017、#5663。

§ 19

⚠️ proto is always stripped

Object and record parsers now drop a proto key whether it comes from the input, is declared by the schema, or is produced by a record key transform. A key that a record's key schema normalizes to proto is dropped too. .strict() reports an own proto input key as unrecognized_keys instead of silently swallowing it. Error formatters and both JSON Schema converters use own-property writes so a toString or constructor path segment can't walk onto Object.prototype (#6213, #6367, #6346). (#6386, #6354, #6355, #6221)

⚠️ proto 一律被移除

对象和 record 解析器现在会丢弃 proto 键,无论它来自输入、由 schema 声明,还是由 record 键转换产生。如果 record 的键 schema 把某个键规范化成了 proto,该键同样会被丢弃。.strict() 会把输入中自有的 proto 键报告为 unrecognized_keys,而不是静默吞掉。错误格式化器和两个 JSON Schema 转换器都改用自有属性写入,因此 toString 或 constructor 路径段不会走到 Object.prototype 上(#6213、#6367、#6346)。(#6386、#6354、#6355、#6221)

§ 20

⚠️ Stricter string formats

z.ipv6() validated by handing the string to new URL(), which let ::@1\ and ::1\n through. It now checks the address alphabet directly (#6442).

z.ulid() restricts the first character to 0–7; anything higher overflows the 48-bit timestamp. A fixture that doesn't start with a real timestamp, such as one with a leading letter, is now rejected (#6095).

z.httpUrl() enforces the RFC 1035 length limits on the host, matching z.hostname() (#6035).

z.emoji() no longer backtracks exponentially on a failed match (#6347).

z.string().includes(sub, { position: N }) emits a JSON Schema pattern that allows at least N leading characters, matching String.prototype.includes (#6024).

⚠️ 字符串格式校验更严格

z.ipv6() 此前通过把字符串交给 new URL() 来校验,导致 ::@1\ 和 ::1\n 能通过;现在直接检查地址字母表。(#6442)

z.ulid() 限制首字符必须是 0–7;更高的字符会让 48 位时间戳溢出。开头不是真实时间戳的测试数据(例如首字符是字母)现在会被拒绝。(#6095)

z.httpUrl() 对主机名强制 RFC 1035 长度限制,与 z.hostname() 一致。(#6035)

z.emoji() 在匹配失败时不再指数级回溯。(#6347)

z.string().includes(sub, { position: N }) 生成的 JSON Schema pattern 允许至少 N 个前导字符,与 String.prototype.includes 行为一致。(#6024)

§ 21

Zod 4.5 rolls up 155 commits. Thanks to everyone who contributed: @dokson, @deepshekhardas, @zirkelc, @francisjohnjohnston-web, @MerlijnW70, @codinsonn, @oimo23, @JSap0914, @zelinewang, @abhishek-chaudhary2003, @spokodev, @Mohammad-Faiz-Cloud-Engineer, @hamed-bavar, @MGPOCKY, @ChiChuRita, @dinwwwh, @thristhart, @tsmartin9, @vedanshshetti, @belicam, @frastefanini, @andersk, @musaddiq-rafi, @tachmyratsaparmyradov, @arvindfroi, @KUMachine, @spidersouris, @catdalfonso, @mneetika, @gwagjiug, @MahinAnowar, @MaksZhukov, @emmayusufu, @agcty, @devareddy05, @Vish05, @yamcodes, @mattiasahlsen, @samchungy, @ozzyfromspace, @udohjeremiah, @patrickwehbe, @gajus, @Harm-Nullix, @thwbh, @IdanGonen, @irfanfandi, @JuerGenie, @marcalexiei, @itsahmedbilal, @DucMinhNe, @meliharik.

9782f87c perf(v4): validate without building the output, and keep schemas out of dictionary mode (#6480) by @colinhacks

773a4867 refactor(v4): declare a trait's members on $constructor (#6478) by @colinhacks

68fb3f13 feat(v4): make z.compile() fall back instead of throwing (#6479) by @colinhacks

37b01501 feat(v4): add z.isValid and z.isValidAsync (#6471) by @colinhacks

749f5452 docs: add fullproduct.dev to v4 ecosystem page (#6001) by @codinsonn

24cdb7fd perf(v4): close the fastpass bindings into the compiled parser (#6464) by @colinhacks

8d896186 fix(v4): stop emitting a multipleOf that JSON Schema rejects (#6468) by @colinhacks

43f729db feat(v4): make a tuple's items optional with .partial() (#6465) by @colinhacks

97edaf7d fix(v4): don't throw from safeParse on bigint multipleOf(0n) (#6466) by @colinhacks

21a6f0cb feat(v4): let z.nanoid() take a custom length (#4004) by @oimo23

9d5b20ef fix(v4): restrict the first ULID character to [0-7] (#6095) by @JSap0914

1cf9cd09 docs: record that error maps run per parse, and how to translate at render by @colinhacks

7ce3e77d fix(v4): run a wrapper's inner schema on its own payload (#6462) by @colinhacks

7b612b53 fix(v4): fold an intersection of object schemas into one object (#6461) by @colinhacks

1c43b774 docs(v4): record why the failure path is not worth compiling by @colinhacks

badf0b78 fix(v4): build the catch context from the input that failed (#6192) by @zelinewang

a87ac366 fix(v4)!: distinguish number and bigint formats at the type level (#6052) by @abhishek-chaudhary2003

6726c1dd docs: record what z.input and z.output do with transforms and wrappers by @colinhacks

7cfc0122 fix(v4): keep a wrapper's stored value only on the side it belongs to by @colinhacks

a825c1b0 fix(v4): empty enums and literals match nothing (#6459) by @colinhacks

7c070db9 feat(v4): expose the function schema on .implement() results (#6267) by @deepshekhardas

3a496968 fix(v4): make record input keys optional when the value can fill them (#6460) by @colinhacks

53cec2a0 fix(v4): resolve z.input past a preprocess transform by @colinhacks

2125d30c fix(v4): accept exact decimal multiples in multipleOf (#6223) by @spokodev

168122fc fix(v4): carry a pipe's own checks through z.output by @colinhacks

51a1368a fix(v4): let the includes(position) pattern match at or after the offset (#6024) by @francisjohnjohnston-web

72a05c4f feat(v4): expose stringbool truthy/falsy/case via _zod.bag (#6357) by @hamed-bavar

036b39f4 fix(v4)!: require seconds once a datetime carries a Z or an offset (#6457) by @colinhacks

5825605e perf(v4): skip the eager stack capture when building a ZodError (#6450) by @colinhacks

d85472c4 feat(v4): support declared symbol keys in z.object() (#6448) by @colinhacks

d4108872 fix(v4): correct the date/time format keywords in both JSON Schema directions (#6452) by @colinhacks

555e5f46 Add z.toZod helper (#5913) by @colinhacks

e0e51a55 docs(v4): cut the compile comments down to what they explain (#6449) by @colinhacks

6574e784 fix(v4): stop catch resurrecting issues an optional already resolved (#6440) by @colinhacks

937b5d01 perf(v4): prefix issue paths in place in the object JIT failure path (#6445) by @colinhacks

b63db248 fix(v4): keep a memoized node's cached issues private to the cache (#6443) by @colinhacks

6ec3d043 fix(resolution): keep pnpm's own warnings out of the attw snapshot (#6446) by @colinhacks

830ba314 fix(v4): validate the address, and return the string that was validated (#6442) by @colinhacks

f101d8ca Preserve callsites in parse stack traces (#5910) by @colinhacks

6c77d028 feat: compact simple anyOf unions to type array in toJSONSchema (#6339) by @deepshekhardas

28e1ebd8 fix(v4): measure string length in Unicode code points (#6441) by @colinhacks

060bc9f3 refactor: share default when-clauses for size/length checks (#6394) by @zirkelc

2848177d docs: point the flattened/formatted error deprecations at a symbol that exists by @colinhacks

3c2dee9e Add properties checks for instanceof schemas (#5912) by @colinhacks

87ffeb0f fix(v4): an absent key on the middle rung supplies nothing (#6434) by @colinhacks

7785fc82 feat(v4): add z.getDiscriminatedOption (#5947) by @dokson

0135c85a feat(v4): allow passing extra args to apply() (#6337) by @deepshekhardas

ca246d26 fix(v4): drop empty alternation branch from datetime pattern (#6439) by @colinhacks

e073d55b docs: z.iso.datetime() accepts a subset of ISO 8601, not all of it by @colinhacks

d6ca12ae fix(v4): infer recursive getter options in discriminatedUnion (#6422) by @colinhacks

dc51404b Add shorn to Zod Utilities (#6398) by @ChiChuRita

580111da docs: mark AOT compilation as canary-only by @colinhacks

6b0dae79 docs: note that a catch callback is not islanded by @colinhacks

898c4461 refactor(v4): give the runtime and compiled code one URL implementation by @colinhacks

260e5d4b fix(v4): stop islanding a catch callback, which diverged silently by @colinhacks

11c9268b revert(core): drop the exactOptional parse prototype from #6432 (#6438) by @colinhacks

a38ab4a8 fix(core): an omittable discriminator claims undefined (#6432) by @colinhacks

c9ec89e0 perf(core): drop the seal and the per-key WeakSet from the lazy internals (#6435) by @colinhacks

3c9ca1d9 feat(json-schema): emit a root $ref when the root schema has an id (#6029) by @dinwwwh

fa77a4d7 feat(v4): z.compile — ahead-of-time schema compilation (#6085) by @colinhacks

f300476d fix(v4): let a schema's error map cover its own checks' issues (#6426) by @colinhacks

9f0a3d81 fix(core): restore defineLazy semantics lost in the internals move (#6429) by @colinhacks

604464c3 fix(locales): da/nn/no/sv called an IP address a range (#6430) by @colinhacks

7378e7cd fix(locales): backfill the mac and Sizable.map gaps, and pin dictionary parity (#6427) by @colinhacks

b1077f05 perf(memory): install derived internals on a per-constructor prototype (#6415) by @colinhacks

ccc15144 fix(locales): add the credit_card key to the seven locales missing it (#6424) by @colinhacks

73bacbbb fix(from-json-schema): drop redundant inclusive bound for draft-04 exclusive ranges (#6022) by @francisjohnjohnston-web

86b2e6da docs: list el and hr in the supported locales (#6423) by @colinhacks

45fdeda5 fix(v4): refine optin into a three-rung ladder, retire the fallback payload flag (#6419) by @colinhacks

5b34c0ce Improve Portuguese localization and add Brazilian Portuguese (pt-BR) (#6076) by @thristhart

dc1a40a5 fix(locales): improve french translation (#6120) by @tsmartin9

0175a043 feat(locales): add Hindi and Kannada locale support (#6315) by @vedanshshetti

536ee3b0 Locales: added Slovak (sk) language (#6041) by @belicam

07b0c3d8 fix: preserve explicit superRefine issue input (#6053) by @frastefanini

ba98071c feat: add .exactPartial() to ZodObject (#6065) by @andersk

234c407d feat(lang): Added Bengali locale (#5974) by @musaddiq-rafi

377cd9d7 feat(locales): add turkmen (tk) locale (#6168) by @tachmyratsaparmyradov

69b6bb08 feat(locales): add Norwegian Nynorsk (nn) locale (#6092) by @arvindfroi

33d82e6b Add Central Kurdish (ckb) locale (#6078) by @KUMachine

06666fe2 fix(fr): remove hyphen in "non-optionnel" (#5999) by @spidersouris

79cfedea feat(v4): expose the owning schema on check-originated issues (#6420) by @colinhacks

436b5da8 docs: propose compiled constructor graph by @colinhacks

eb4682c9 fix(json-schema): resolve tuple minItems past transform and catch in input mode (#6418) by @colinhacks

4d6b5cd3 fix(json-schema): route unrepresentable default values through unrepresentable by @colinhacks

2abc9e05 docs: note that the JSON Schema emitter reads static optin (#6417) by @colinhacks

578e1cd0 feat(v4): support format: "hostname" in fromJSONSchema (#6305) by @catdalfonso

942bf8cb feat(v4): parse input containing reference cycles (#6387) by @colinhacks

78b523f0 fix(json-schema): keep preprocess object properties required in input mode (#6133) by @MerlijnW70

973b1b44 fix(v4): strip output-typed catch values from the input JSON Schema (#6409) by @colinhacks

5e608851 feat(v4): add z.deepPartial and runtime z.input / z.output (#5928) by @dokson

4e1720c8 fix(v4): align record keys and intersection strictness with TypeScript (#6412) by @colinhacks

4cc4053d fix: honor loose mode for closed record key schemas (#6157) by @pullfrog[bot]

69be843f fix(v4): stop the object JIT fastpass keeping a swallowed issue's value (#6407) by @colinhacks

b899cd17 perf(json-schema): make toJSONSchema(registry) linear in registry size (#6408) by @colinhacks

6074828e fix(v4): make fromJSONSchema propertyNames compose with the other object keywords (#6411) by @colinhacks

d7b209f3 docs: point the Web URLs callout at z.httpUrl() (#6410) by @colinhacks

611bd762 fix(mini): make merge() take an object schema, matching classic (#6404) by @colinhacks

b53e53cc fix(v4): use exact flag in English locale too_small/too_big messages (#6177) by @pullfrog[bot]

421cc9a5 fix(json-schema): unescape JSON Pointer tokens when resolving $ref (#6402) by @colinhacks

4c27fe87 fix(v4): give z.xor() a distinct error when multiple options match (#6376) by @colinhacks

a106fbe7 fix(v4): make fromJSONSchema tuples open-ended by default (#6020) by @mneetika

e8034eba fix(v4): make prefixItems/draft-7 items respect minItems in fromJSONSchema (#6201) by @pullfrog[bot]

784e5c26 fix(v4): let bundlers tree-shake locales out of the default import (#6384) by @colinhacks

97edd70a fix(toJSONSchema): constrain closed tuple length (#6194) by @pullfrog[bot]

f150020d fix(v4): escape non-string enum values in template literal patterns (#5934) by @gwagjiug

faf33a28 fix: surface @deprecated on re-exported compat aliases (#6072) by @MahinAnowar

3956224a docs: state that metadata wins over generated JSON Schema keywords (#6401) by @colinhacks

a1904fc2 fix(v4): report date origin for numeric min/max bounds (#6129) by @MerlijnW70

bd18314c fix: escape JSON Pointer reserved characters in toJSONSchema $ref (closes #6027) (#6144) by @MaksZhukov

2a5164f5 fix(v4): enforce RFC 1035 length limits in regexes.domain (#6035) by @emmayusufu

0e5bc4b1 fix(v4): respect additionalProperties:false with patternProperties in fromJSONSchema (#6199) by @pullfrog[bot]

c8f06d36 fix(v4): clarify infinite number errors (#5906) by @colinhacks

9a7ecc35 fix(json-schema): accept RFC 3339 numeric offsets in date-time format (#6298) by @agcty

0a76f3d7 feat(v4): add z.creditCard() string format (#5931) by @dokson

bd6619c0 feat(json-schema): accept a function for unrepresentable (#6380) by @colinhacks

9d20fdc3 fix(v4): preserve z.preprocess input narrowing (#5967) by @devareddy05

3063993a perf(v4): cut per-schema memory ~90% by moving methods to the prototype (#6318) by @zirkelc

fd074106 feat(json-schema): run override before the unrepresentable error (#6391) by @colinhacks

2715c12e fix(v4): preserve default English locale across tree-shaken bundles (#5959) by @colinhacks

81d9fc6c docs: add zod-form-action to ecosystem (#6314) by @Vish05

d86df5e0 docs: add ArkEnv to ecosystem page (#6203) by @yamcodes

18b4ff99 docs(ecosystem): add zodql to API Libraries (#6227) by @mattiasahlsen

479d6f51 shill oxlint (#6196) by @samchungy

85dba7e1 docs: document that any/unknown object keys are required (#6388) by @colinhacks

d24fb4c3 fix: consistently strip proto from parsed objects (#6386) by @colinhacks

7708d447 perf(v4): lazy ZodError construction (#6316) by @zirkelc

8ac9ae51 fix(docs-v3): serve the docsify SPA fallback on Vercel (#6378) by @colinhacks

31384464 fix(v4): complete reserved-key hardening (#6371) by @colinhacks

600c6909 docs: add Attaform to ecosystem (#6188) by @ozzyfromspace

37c05fa5 docs(ecosystem): rename zod-to-mongo-schema to zod-mongo-schema (#6178) by @udohjeremiah

badfdf08 docs: update keyof() ZodEnum type to the v4 form (#6124) by @patrickwehbe

e25b68e1 perf(v4): let three dead declarations tree-shake under esbuild (#6381) by @colinhacks

53397351 docs(ecosystem): Add zod-mongoose list item in Zod To X (#6062) by @Harm-Nullix

dfa0deb1 docs: add tauri-typegen to ecosystem (#6032) by @thwbh

9c914ee8 docs: add dynamic error message and combined refinement examples for refine() (#6002) by @IdanGonen

921649de fix(v4): formatError and treeifyError handle inherited-name path elements (#6367) by @deepshekhardas

e7029aa4 fix(v4): report own proto key under .strict() (#6221) by @pullfrog[bot]

9c540db8 fix(v4): re-check the record key after the key schema runs (#6355) by @colinhacks

8bb89ea4 docs: add .nonempty() to Strings, Arrays, Sets, and Maps sections (#6056) by @pullfrog[bot]

599c0e41 docs(ecosystem): Add @chrock-studio/overload and @chrock-studio/zod-utils (#6040) by @JuerGenie

27a9036a docs(ecosystem): eslint-plugin-zod is eslint-zod now (#5975) by @marcalexiei

e177a0ee docs(v4): document coerce missing-key breaking change (#5957) (#5964) by @dokson

66fba964 docs: show z.instanceof with built-in classes (#6059) by @itsahmedbilal

2d90846a fix(docs): make the prefault example runnable (#6063) by @DucMinhNe

ead9fcb3 fix(v4): write a declared proto key as an own property (#6354) by @colinhacks

c58764c5 docs: fix UUID helper list in v4 introduction (#6214) by @meliharik

f238fbd2 fix: remove exponential backtracking from the emoji regex (#6347) by @colinhacks

e6c213ec fix(json-schema): keep proto keys as own properties in schema conversion (#6346) by @colinhacks

573fcb75 fix(errors): use own-property semantics in every error-tree walker (#6213) by @pullfrog[bot]

6f5e99fd fix(docs-v3): rename README.md to home.md so Vercel serves it by @colinhacks

bbc68f99 docs: soften Zod 3 EOL callouts to informational tone by @colinhacks

3fc9b25f docs: reframe library-authors page Zod-4-first; note Zod 3 EOL by @colinhacks

f29f2a6d fix(v4): cidrv6 JSON schema pattern matches runtime (#5945) by @dokson

dfd8766b fix(v4): break circular import between classic schemas and iso (#5275) (#5926) by @dokson

fbe8ad1b fix(v4): allow dynamic .catch() under unrepresentable: "any" (#5273) (#5925) by @dokson

Zod 4.5 汇总了 155 个提交。感谢所有贡献者:@dokson、@deepshekhardas、@zirkelc、@francisjohnjohnston-web、@MerlijnW70、@codinsonn、@oimo23、@JSap0914、@zelinewang、@abhishek-chaudhary2003、@spokodev、@Mohammad-Faiz-Cloud-Engineer、@hamed-bavar、@MGPOCKY、@ChiChuRita、@dinwwwh、@thristhart、@tsmartin9、@vedanshshetti、@belicam、@frastefanini、@andersk、@musaddiq-rafi、@tachmyratsaparmyradov、@arvindfroi、@KUMachine、@spidersouris、@catdalfonso、@mneetika、@gwagjiug、@MahinAnowar、@MaksZhukov、@emmayusufu、@agcty、@devareddy05、@Vish05、@yamcodes、@mattiasahlsen、@samchungy、@ozzyfromspace、@udohjeremiah、@patrickwehbe、@gajus、@Harm-Nullix、@thwbh、@IdanGonen、@irfanfandi、@JuerGenie、@marcalexiei、@itsahmedbilal、@DucMinhNe、@meliharik。完整提交列表见英文侧对应段落。

Open source ↗