Zod vs Yup
Validation.
Overview
Zod and Yup are the two most-used JS/TS schema validation libraries. Zod is TypeScript-first (schemas double as TS types via inference, no duplication between schema and type); Yup is the longer-established choice with a broader plugin ecosystem and Formik-friendly APIs. The right answer depends on whether type inference is the priority or whether the team is already invested in the Yup ecosystem.
- Zod: TypeScript-first inference.
z.infer<typeof schema>derives the TS type from the schema. No duplication between schema and type. - Yup: longer history. Decade of production use, broad plugin ecosystem, idiomatic with Formik. Default for legacy React form stacks.
- Operational fit per team. Existing form libraries and team TS expertise bias the choice. Both libraries are stable.
- Per-codebase choice. Different codebases may pick differently. Document the rationale per codebase rather than enforcing one library across all of them.
The approach
Workload-driven choice, per-team operational fit considered, documented rationale per codebase. The discipline is making the validation library choice once with a written reason rather than mixing both libraries in the same codebase.
- Workload-driven. Library per codebase. Reality drives the answer.
- Zod for TypeScript-heavy codebases. Type inference removes the schema/type duplication. Default for new TS projects.
- Yup for legacy or Formik-driven codebases. Existing investment plus form-library integration. Default when migration cost outweighs inference benefits.
- Operational fit plus documented rationale. Team workflow considered; per-codebase rationale captured. Future migrations have a paper trail.
Why this compounds
The right validation library compounds across years. Schema patterns and team expertise align with the library; cross-cutting concerns (error formatting, i18n, async validation) get built once and reused. By year two the library choice is automatic per codebase.
- Better operational fit. Library matches team. Velocity stays high.
- Workload-driven decisions. Replaces tribal preference with documented rationale. Quality of choice improves.
- Better engineering velocity. Right library means schemas compose cleanly. Iteration speed increases.
- Year-one investment, year-two habit. First library choice is the investment; subsequent codebases inherit the patterns.