Zod v4 introduces a new minimalist API through @zod/mini that follows a more functional approach. This tool helps you migrate your existing Zod v3 codebase to the new format with minimal effort.
npx zod-to-mini-converterRun the command in the root of your project to migrate all your files to the new format.
By default, the tool uses your project's tsconfig.json for configuration. You can specify a different tsconfig path if needed:
npx zod-to-mini path/to/custom/tsconfig.json- Imports: Replaces imports from
zodwith@zod/mini - Validation methods: Replaces method chaining with the new functional
checkpipe syntax - Deprecated methods: Updates deprecated methods with their newer equivalents
- Method mappings: Transforms method names according to the new API
Before:
import * as z from 'zod';
const userSchema = z.object({
username: z.string().min(3).max(20),
email: z.string().email(),
age: z.number().min(18).optional(),
});After:
import * as z from '@zod/mini';
const userSchema = z.object({
username: z.string().check(z.minLength(3), z.maxLength(20)),
email: z.string().check(z.email()),
age: z.optional(z.number().check(z.gte(18))),
});If you use any of the following methods in your Zod schemas, then these methods will not be migrated.
After the migration there will be compilation errors that need manual adjustments.
If you need these methods, you can use the zod package.
transformcoercedefault
Contributions are welcome! If you find any issues or have suggestions for improvements, please open an issue or submit a pull request.
Found an issue? Please open an issue.