Zod (web)
Zod is a TypeScript-first schema declaration and validation library that lets developers define a schema once and get both runtime validation and static type inference from it.
Definition
Zod is a TypeScript-first schema declaration and validation library that lets developers define a schema once and get both runtime validation and static type inference from it.
Overview
Zod addresses a common gap in TypeScript applications: types only exist at compile time, so data coming from forms, APIs, or environment variables still needs runtime checks. With Zod, a developer defines a schema using a fluent API (`z.object`, `z.string`, `z.number`, and so on), and Zod both validates values against that schema at runtime and infers a matching static TypeScript type via `z.infer`, eliminating the need to maintain types and validators separately. Schemas can be composed, extended, and transformed — objects can be merged, unions and discriminated unions modeled, and custom refinements added for rules that go beyond basic type checks. Parsing methods return either a validated, typed value or a structured list of issues, which makes Zod convenient for form libraries: resolvers exist for React Hook Form and other tools so a single schema can validate form input, API request bodies, and environment configuration. Zod's combination of type inference and runtime safety has made it one of the most widely adopted validation libraries in the modern React and Node.js ecosystem, often displacing older schema libraries like Yup in new TypeScript-first projects.
Key Features
- TypeScript-first design with automatic static type inference from schemas (z.infer)
- Fluent, chainable API for defining objects, arrays, unions, and primitives
- Built-in and custom validation rules via refinements and transforms
- Structured, detailed error reporting for failed validations
- Composable schemas that can be merged, extended, or reused across the codebase
- Zero runtime dependencies and a small footprint
- Resolver integrations for form libraries like React Hook Form