zod-4

Migrate TypeScript projects from Zod v3 to Zod v4 APIs and patterns.

Updated Jul 10, 2025
One-click install
npx skills add https://github.com/SoyJuanMa/Nvim_Back --skill zod-4-soyjuanma
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: zod-4
Source: https://github.com/SoyJuanMa/Nvim_Back/tree/main/opencode/skill/zod-4
Command: npx skills add https://github.com/SoyJuanMa/Nvim_Back --skill zod-4-soyjuanma

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Migrating from Zod v3 to Zod v4 can be tricky due to breaking API changes; this guide showcases patterns and examples to implement Zod 4 validation across common use cases in TypeScript projects.

Core Features & Use Cases

  • Updated primitives and top-level validators for Zod 4 (e.g., z.email(), z.uuid(), z.url()) and improved constraints.
  • Comprehensive object, array, record, tuple, and union schemas with migration notes and practical examples.
  • Guidance on transformations, refinements, optional/nullable handling, and integration with React Hook Form for modern front-end apps.

Quick Start

Refactor a sample Zod v3 schema to Zod v4 in your TypeScript project.

Frequently Asked Questions about zod-4

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I migrate TypeScript validation schemas from Zod v3 to Zod v4?

Migrate Zod v3 schemas to Zod v4 by adopting updated APIs for primitives, objects, arrays, unions, transformations, and refinements to ensure compatibility and type safety.

What are the new primitive validators in Zod v4?

Zod v4 introduces top-level primitive validators like z.email(), z.uuid(), and z.url(), replacing older string format patterns and providing improved constraints for TypeScript validation.

How does Zod v4 handle optional and nullable fields in object schemas?

Zod v4 updates optional and nullable handling within object schemas, offering refined migration patterns that maintain type safety while simplifying how undefined or null values are processed.

Can I integrate Zod v4 schemas with React Hook Form?

Yes, Zod v4 integrates with React Hook Form by applying migrated schema patterns to validate form inputs, ensuring type safety across modern front-end TypeScript applications.

Does Zod v4 support custom transformations and refinements?

Zod v4 continues to support custom transformations and refinements, providing updated migration notes and practical examples to implement complex validation logic correctly.

What are common breaking changes when upgrading to Zod v4?

Breaking changes in Zod v4 include updated primitive validators, modified object and array schemas, and revised error handling, requiring careful migration to avoid TypeScript type issues.