Zod vs Yup
Which schema validation library should you use for your TypeScript project?
Comparison Table
| Zod | Yup | |
|---|---|---|
| TypeScript-first | ✓ Yes — types inferred from schema | Partial — requires separate types |
| Type inference | Automatic with z.infer<> | Manual (@types/yup or separate types) |
| Bundle size | ~14 KB (min+gzip) | ~23 KB (min+gzip) |
| Sync validation | ✓ parse() and safeParse() | Requires .validateSync() |
| Async validation | ✓ parseAsync() | ✓ .validate() (default async) |
| Error format | Flat errors via .flatten() | Nested errors via .inner |
| tRPC integration | ✓ Official support | Community support |
| React Hook Form | ✓ @hookform/resolvers/zod | ✓ @hookform/resolvers/yup |
| Next.js / Astro | ✓ Common pairing | ✓ Works fine |
| Performance | Generally faster | Slightly slower |
| Ecosystem maturity | Newer (2020), fast growing | Older (2016), established |
| Custom transforms | ✓ .transform() | ✓ .transform() |
Defining the Same Schema
Zod
import { z } from 'zod';
const UserSchema = z.object({
name: z.string().min(2),
email: z.string().email(),
age: z.number().int().min(18),
});
// TypeScript type inferred automatically
type User = z.infer<typeof UserSchema>;
// Parse
const user = UserSchema.parse(data);
// Safe parse
const result = UserSchema.safeParse(data);
if (result.success) {
console.log(result.data.name);
}Yup
import * as yup from 'yup';
const UserSchema = yup.object({
name: yup.string().min(2).required(),
email: yup.string().email().required(),
age: yup.number().integer().min(18).required(),
});
// TypeScript type requires manual inference
type User = yup.InferType<typeof UserSchema>;
// Validate (async by default)
const user = await UserSchema.validate(data);
// Validate without throwing
const isValid = await UserSchema.isValid(data);Choose Zod if:
- ✓ You are using TypeScript (it was designed for TS)
- ✓ You want types inferred from schemas, not defined twice
- ✓ You use tRPC, Next.js, or Astro
- ✓ You need synchronous validation (parse/safeParse)
- ✓ You want a smaller bundle
- ✓ Starting a new project from scratch
Choose Yup if:
- ✓ You have an existing codebase already using Yup
- ✓ Your team knows Yup well
- ✓ You rely heavily on async validation by default
- ✓ You are using Formik (Yup is the official pairing)
Frequently Asked Questions
Is Zod better than Yup for TypeScript?
Zod is generally better for TypeScript projects. Types are inferred from schemas automatically with z.infer<> — no need to maintain separate type definitions alongside validation schemas.
Is Zod faster than Yup?
Zod is generally faster than Yup. Benchmarks show Zod parses simple schemas 2-5x faster, though both are fast enough for typical application use.
Can I use Yup and Zod in the same project?
Technically yes, but not recommended. Using both adds unnecessary bundle size and cognitive overhead. Pick one and use it consistently. For new TypeScript projects, Zod is the better choice.
Does Zod work with Next.js server actions?
Yes. Zod is commonly used with Next.js server actions and API routes. Parse incoming FormData or request bodies with Zod before processing. Use safeParse() to return typed validation errors to the client.
Which is better for Formik — Zod or Yup?
Yup is the officially recommended library for Formik. Formik's docs and examples use Yup. Zod can work with Formik via a custom resolver, but Yup is the easier and better-supported choice for Formik-based forms.
Is Zod or Yup better with React Hook Form?
Both work with React Hook Form via resolvers (@hookform/resolvers). Zod is increasingly preferred in new projects because of its TypeScript-first design and z.infer type inference. Yup remains popular in existing Formik-based projects. The RHF documentation shows both.
Can I use Yup with TypeScript?
Yes. Yup has TypeScript support and can infer types via yup.InferType<typeof schema>. However, Yup's type inference is less precise than Zod's for complex schemas (unions, discriminated unions). Zod was designed specifically for TypeScript-first type inference.
Which is easier to learn: Zod or Yup?
Yup has a more fluent, chainable API that many find intuitive: string().min(3).max(50).required(). Zod is similar: z.string().min(3).max(50). Both have similar learning curves. Zod's TypeScript integration is cleaner, making it more productive in TS projects.
From the blog
View all →
Jun 8, 2026
JavaScript Object to JSON: Serialization Patterns and Common Pitfalls

Jun 8, 2026
TypeScript to JavaScript: When and How to Strip Types

Jun 4, 2026
JavaScript Object to JSON: Serialization Patterns and Common Pitfalls

Jun 4, 2026
TypeScript to JavaScript: When and How to Strip Types

Jun 1, 2026
JSON to TypeScript: Auto-Generate Interfaces from API Responses
Generate a Zod schema from your JSON data?
Use the JSON to Zod Converter →