feat(v4): add .validate() and .validateAsync() to Zod Classic (#6547)
* feat(v4): add .validate() and .validateAsync() methods to Zod Classic `z.validate(schema, data)` has existed as a top-level function since 4.5, but there was no method form. Add both to the classic `ZodType`, delegating to the same core functions. `.validate()` keeps the type-guard: it narrows to `core.input<this>`, so a `this`-based predicate on the interface. `ProtoOf` erases the predicate when it maps the interface onto the member table, so the implementation entry is a plain boolean return with no cast. Classic only. `zod/mini` stays function-based and is byte-identical: both mini treeshake fixtures measure 3001 and 4576 gz, unchanged. The classic `zod-object` fixture grows 176 B gz (25113 -> 25289), because the prototype reference now retains the validate implementation that a classic bundle previously shook out. Schema footprint and dict-mode are unchanged, and the prototype descriptor surface gains only the two new accessors. * docs: lead the validate section with the method form basics.mdx told classic users to reach for the top-level function, which is no longer the shortest path now that the method exists. The function is still named once, since it is what zod/mini uses. * Drop the async wrapper on validateAsync, and lead the docs with the mini form validateAsync only forwarded a promise, so `async` bought a second promise and a microtask hop for nothing: 64.3 ns against 31.9 ns per call, interleaved and warmed, min of 9 rounds. safeParseAsync has the same removable wrapper, which is left alone here. The bundle is not part of it — the keyword is a byte or two after gzip, and the fixtures move ±1 B. basics.mdx names the top-level form in the sentence that introduces the method, rather than after the example, so a Zod Mini reader does not copy a method their import does not have.
C
Colin McDonnell committed
62e6624bc72c4882968ac4ea2c4281b1a99a7ad4
Parent: cafbee4
Committed by GitHub <noreply@github.com>
on 9/1/2026, 8:18:21 PM