What problem does it solve?
Migration and compatibility gaps when upgrading from Zod 3 to Zod 4 cause TypeScript type errors, runtime validation regressions, and confusing API differences that break validation logic across a codebase. This guide consolidates breaking changes, migration patterns, and troubleshooting steps to reduce manual edits and test failures during the upgrade.
Core Features & Use Cases
- Breaking Changes Reference: Clear, prioritized explanations for high-impact changes such as the new z.record signature, removed .strict()/.passthrough(), and .default() behavior changes.
- Migration Checklist & Patterns: Step-by-step fixes for common code patterns including record schemas, strict vs loose object shapes, error formatting updates, and transform/default interactions.
- Codemod & Automation Guidance: Advice on running a community codemod, search-and-replace patterns, and verifying TypeScript and runtime behavior after changes.
- Feature Adoption & Optimization: Introduces Zod 4 new features (z.file, z.templateLiteral, .meta, z.globalRegistry) and the lighter zod/mini import for bundle-size improvements.
- Troubleshooting & Testing: Practical checks for TypeScript version requirements, test strategies, and runtime error resolution examples.
Quick Start
Convert all single-argument z.record calls to the two-argument form, replace .strict() and .passthrough() with z.strictObject and z.looseObject respectively, update error handling to use z.treeifyError, run the zod-v3-to-v4 codemod where helpful, and execute the test suite to validate changes.