API Reference
Zod
TypeScript-first schema validation with static type inference for runtime data parsing and form validation.
Official Documentation ↗CompatibilityThis documentation covers version
v3.23. Check the official docs for the latest API surface.Installation
npm
npm install zodpnpm
pnpm add zodyarn
yarn add zodMethods
No methods match this filter.
Zod is a TypeScript-first schema validation library that provides static type inference from runtime schemas. It enables you to define a schema once and derive both the TypeScript type and runtime validation from it, eliminating type drift. Zod is isomorphic and works seamlessly on both client and server.
Key Features
- Type inference:
z.infer<typeof schema>auto-generates types from schemas - Composable: Schemas can be composed with
.extend(),.merge(),.pick(),.omit() - Rich type support: Strings, numbers, dates, enums, arrays, objects, unions, intersections
- Error customization: Detailed error mapping with
ZodErrorandz.setErrorMap() - Zero dependencies: No external runtime dependencies
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.
Report a problem with this API docOpens a pre-filled issue on GitHub.