Zod
TypeScript-first schema validation with static type inference
README
Zod
✨ https://zod.dev ✨
TypeScript-first schema validation with static type inference
These docs have been translated into Chinese.
Table of contents
<!-- The full documentation is available both on the official documentation site (recommended) and inREADME.md.
Go to zod.js.org >> -->
- Sponsors
- Node/npm
- Deno
- Literals
- Strings
- Numbers
- NaNs
- Booleans
- Dates
- Objects
- .shape
- .keyof
- .extend
- .merge
- .partial
- .strict
- .strip
- Arrays
- .element
- Tuples
- Unions
- Records
- Maps
- Sets
- Promises
- .parse
- .refine
- .default
- .catch
- .nullish
- .array
- .promise
- .or
- .and
- .brand
- Joi
- Yup
- io-ts
- Runtypes
Introduction
Zod is a TypeScript-first schema declaration and validation library. I'm using the term "schema" to broadly refer to any data type, from a simple string to a complex nested object.
Zod is designed to be as developer-friendly as possible. The goal is to eliminate duplicative type declarations. With Zod, you declare a validator _once_ and Zod will automatically infer the static TypeScript type. It's easy to compose simpler types into complex data structures.
Some other great aspects:
- Zero dependencies
- Works in Node.js and all modern browsers
- Tiny: 8kb minified + zipped
- Immutable: methods (i.e. .optional()) return a new instance
- Concise, chainable interface
- Functional approach: parse, don't validate
- Works with plain JavaScript too! You don't need to use TypeScript.
Sponsors
Sponsorship at any level is appreciated and encouraged. For individual developers, consider the Cup of Coffee tier. If you built a paid product using Zod, consider one of the podium tiers.
Gold
Astro astro.build Astro is a new kind of static | Glow Wallet glow.app Your new favorite |
Deletype deletype.com |
Silver
Snaplet snaplet.dev | Marcato Partners marcatopartners.com | Trip |
Seasoned Software seasoned.cc | Interval interval.com |
Bronze
Brandon Bayer @flybayer, creator of Blitz.js | Jiří Brabec @brabeji | Alex Johansson @alexdotjs |
Adaptable adaptable.io | Avana Wallet avanawallet.com Solana non-custodial wallet |
Ecosystem
There are a growing number of tools that are built atop or support Zod natively! If you've built a tool or library on top of Zod, tell me about it on Twitter or start a Discussion. I'll add it below and tweet it out.
Resources
API libraries
- [tRPC](https://github.com/trpc/trpc): Build end-to-end typesafe APIs without GraphQL.
- [@anatine/zod-nestjs](https://github.com/anatine/zod-plugins/tree/main/packages/zod-nestjs): Helper methods for using Zod in a NestJS project.
- [zod-endpoints](https://github.com/flock-community/zod-endpoints): Contract-first strictly typed endpoints with Zod. OpenAPI compatible.
- [domain-functions](https://github.com/SeasonedSoftware/domain-functions/): Decouple your business logic from your framework using composable functions. With first-class type inference from end to end powered by Zod schemas.
- [@zodios/core](https://github.com/ecyrbe/zodios): A typescript API client with runtime and compile time validation backed by axios and zod.
- [express-zod-api](https://github.com/RobinTail/express-zod-api): Build Express-based APIs with I/O schema validation and custom middlewares.
Form integrations
- [react-hook-form](https://github.com/react-hook-form/resolvers#zod): A first-party Zod resolver for React Hook Form.
- [zod-validation-error](https://github.com/causaly/zod-validation-error): Generate user-friendly error messages from ZodErrors
- [zod-formik-adapter](https://github.com/robertLichtnow/zod-formik-adapter): A community-maintained Formik adapter for Zod.
- [`react-zorm`](https://github.com/esamattis/react-zorm): Standalone `