apiweiser/zod-3-to-4
zod 3 to 4: one-argument z.record, removed AnyZodObject/ZodTypeDef types, required_error/invalid_type_error params and ZodError.errors
# zod-3-to-4
The zod 4 changes that break code ([changelog](https://zod.dev/v4/changelog)),
rewritten mechanically:
```ts
z.record(z.unknown()) // -> z.record(z.string(), z.unknown())
input: z.AnyZodObject // -> input: z.ZodObject (SomeZodObject too)
WeakMap<z.ZodTypeDef, ...> // -> WeakMap<z.core.$ZodTypeDef, ...>
const shape: z.ZodRawShape = {} // -> const shape: Record<string, z.ZodType> = {}
z.string({ required_error: R, invalid_type_error: I })
// -> z.string({ error: (issue) => issue.input === undefined ? R : I })
result.error.errors // -> result.error.issues
```
- zod found through `import { z }`, `import * as z`, `import z`,
`require("zod")` and named imports (`record`, `AnyZodObject`)
- a named `record(V)` gets `string()`, added to the import if needed
- JavaScript and TypeScript files
Not handled: `errorMap` (its signature changed), `.default()` on optional
values, `z.function()`, and libraries that read zod 3 internals - notably
`zod-to-json-schema`, which accepts zod 4 as a peer but doesn't convert its
schemas; replace it with `z.toJSONSchema()` and compare the output. Run the
typecheck and tests.
```sh
npx codemod run @apiweiser/zod-3-to-4 --target .
```