Skip to content

Update zod 3 to zod 4 support in p5.js dev-2.0 #7872

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: dev-2.0
Choose a base branch
from

Conversation

madhav2348
Copy link

@madhav2348 madhav2348 commented Jun 4, 2025

Resolves #7833

Changes:

  • line 325 schema items can be accessed within def
  • line 356 and 360 _def is deprecated, use def or directly use options
  • line 393 zodErrorObj.errors[0] changes to zodErrorObj.issues[0]
  • line 410 union error changes to errors
  • line 414 and 459, received changes to message
  • Test cases are updated. According to zod 4, error messages are elaborated

Important

constant.js have some variable which are Symbols , according to zod 4, Symbols aren't considered literal values, nor can they be simply compared with ===. This was an oversight in Zod 3.

PR Checklist

- line 325 schema `items` can be access within `def`
- line 356 and 360 `_def` is deprecated , use `def` or directly use `options`
 - line 393 `zodErrorObj.errors[0]` changes to `zodErrorObj.errors[0]`
- line 410 `union error` changes to `errors`
- line 414 and 459 , `received` changes to `message`

## Important
In constants.js, Symbols aren't considered literal values, nor can they be simply compared with ===. This was an oversight in Zod 3.
According to zod 4 , error message are more elaborated
Copy link

welcome bot commented Jun 4, 2025

🎉 Thanks for opening this pull request! Please check out our contributing guidelines if you haven't already. And be sure to add yourself to the list of contributors on the readme page!

@madhav2348 madhav2348 changed the title Madhav/issue7833 Update zod 3 to zod 4 support in p5.js dev-2.0 Jun 4, 2025
@ksen0
Copy link
Member

ksen0 commented Jun 4, 2025

Hi @madhav2348 ! Thanks for working on this. From the tests, looks like the zod update in package.json itself isn't part of the PR?

@madhav2348
Copy link
Author

madhav2348 commented Jun 4, 2025

Hi @madhav2348 ! Thanks for working on this. From the tests, looks like the zod update in package.json itself isn't part of the PR?

My apologies, Thank you for figuring out. I was trying to reproduce the failed test case by switching back and forth between Zod 3 and Zod 4 versions to confirm which leads to uncommitted package.json changes.

Copy link
Contributor

@davepagurek davepagurek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for taking this on! Are the changed property names and error types due to the originals no longer existing in zod 4? Just for my own understanding, did you come across any docs explaining those differences?

to match the test cases
- split the error messages, to get a type in line 418 and 462
- `actualType` will never be undefined which is checked in line 394 so make it undefined in line 430 to pass all test cases
@madhav2348
Copy link
Author

Thanks for taking this on! Are the changed property names and error types due to the originals no longer existing in zod 4? Just for my own understanding, did you come across any docs explaining those differences?

I went through the migration docs, but they haven't covered all the changes. The changes I made are by going through the source code of Zod 4.
Please let me know if further adjustments are needed!

Thank you

-  z.function() is no longer a Zod schema. Instead, it acts as a standalone "function factory" for defining Zod-validated functions.
- .def.type checks schema type. If its `'function'`, fallback to `z.any()`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants