.passthrough()
replaces .nonstrict()
and better aligns with Zod’s philosophy of explicitness.meta()
supersedes several ad-hoc helpers such as .describe()
.ZodError
export path and richer error objects.z.union
, z.intersection
) over chained .or()
/ .and()
calls.Install Zod 4
Run the codemod
--dry-run
flag which lets you preview the changes without applying them.var
declarations or debug console.log
statements. Concretely, it performs the following refactors:.nonstrict()
→ .passthrough()
.or()
/ .and()
calls → z.union([...])
/ z.intersection([...])
.describe("…")
→ .meta({ description: "…" })
ZodError
, z.ZodSchema
import paths to the new zod/v4
entrypointsz.lazyobject
, legacy refinements, etc.)Review & test
TODO(zod-4-migration)
comments the codemod leaves behind for ambiguous cases.Before & After examples
From | To | Languages |
---|---|---|
zod@3.22.x | zod@4.0.0 | JavaScript & TypeScript |
.refine()
logic or plugin APIs.