Open navigation menu

Zod

TypeScript-first schema validation with static type inference for runtime data parsing and form validation.

Version: v3.23

Official Documentation ↗

Installation

npmnpm install zod
pnpmpnpm add zod
yarnyarn add zod

Methods

FAQ

What does TypeScript-first mean in Zod?
Zod schemas produce static TypeScript types via z.infer(), eliminating the need to manually define interfaces. The runtime validation and compile-time types are always in sync, preventing type drift.
How does Zod differ from Yup?
Zod is TypeScript-first with automatic type inference, while Yup requires manual type definitions. Zod also supports more types (discriminated unions, records, maps, sets) and has better error customization with ZodError.
Can Zod be used on both client and server?
Yes. Zod is isomorphic and works in browsers, Node.js, Deno, and Bun. The same schema can validate form input on the client and API payloads on the server, ensuring end-to-end type safety.