Skip to content

Migrate to Zod 4#14947

Closed
matthewp wants to merge 7 commits intonextfrom
zod4-final
Closed

Migrate to Zod 4#14947
matthewp wants to merge 7 commits intonextfrom
zod4-final

Conversation

@matthewp
Copy link
Copy Markdown
Contributor

@matthewp matthewp commented Dec 2, 2025

WIP - early stages, ignore for now

Changes

  • TODO

Testing

Docs

- Update all z.record() calls to include key schemas
- Fix z.function() API from tuple to object syntax
- Replace .strict()/.passthrough() with z.strictObject()/z.looseObject()
- Fix ZodError.errors → .issues usage in loaders
- Fix ActionInputError generic type parameter
- Remove zod-to-json-schema dependency, use native z.toJSONSchema()
- Fix z.looseObject() schema._def property access issues
- Update i18n.ts to handle looseObject type inference
- Fix safeParseAsync usage in content/utils.ts

Errors reduced from 190+ to 38 remaining, primarily type inference issues with z.looseObject() returning Record<string|number|symbol, T> keys
- Replace z.strict() with z.strictObject() and z.passthrough() with z.looseObject()
- Update z.function() calls to object syntax: {input: [...], output: ...}
- Change ZodError.errors to .issues everywhere
- Update z.record() calls to include both key and value schemas
- Remove errorMap parameter from parseAsync() calls (no longer supported)
- Fix ZodErrorMap callback signature with as any cast
- Add @ts-expect-error for Zod 4 RefinementCtx.path type issue
- Cast z.looseObject() results with as any where type inference fails
- 53 errors reduced to 3 remaining (type definition issues, not Zod API)
@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Dec 2, 2025

⚠️ No Changeset found

Latest commit: c5bb4ac

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@github-actions github-actions bot added pkg: integration Related to any renderer integration (scope) pkg: astro Related to the core `astro` package (scope) docs pr labels Dec 2, 2025
- Update z.record() to use 2-arg form (key, value schema)
- Update z.function() to use { input: [], output: schema } syntax
- Replace .error.errors with .error.issues in Zod 4
- Remove errorMap option parameters (not supported in Zod 4)
- Add type assertions for complex generic constraints
- Fix .default() to support function form in integration config
- Fix formDataToObject to check `_def.catchall` instead of `unknownKeys` for passthrough detection in Zod 4
- Fix handleFormDataGetAll to use `_def.element` instead of `_def.type` for accessing array element validators in Zod 4
- Update config-validate tests to use `.issues` instead of `.errors` for ZodError in Zod 4
- Changed errorMap from Zod 3's (baseError, ctx) to Zod 4's (iss) signature
- Updated z.config() to use customError callback instead of z.setErrorMap()
- Use iss.input instead of received for invalid_type/invalid_literal errors
- Show received type name instead of actual value for type mismatch errors
- Add handling for too_small errors in validation
- Add error handling in customError callback to fallback gracefully
@florian-lefebvre florian-lefebvre linked an issue Dec 3, 2025 that may be closed by this pull request
1 task
@florian-lefebvre florian-lefebvre mentioned this pull request Dec 3, 2025
23 tasks
@florian-lefebvre florian-lefebvre added this to the v6.0.0 milestone Dec 4, 2025
@matthewp matthewp closed this Dec 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs pr pkg: astro Related to the core `astro` package (scope) pkg: integration Related to any renderer integration (scope)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support Zod 4

2 participants