Skip to content
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

Joi vs Yup comparison of core schemas #1800

Open
HamzaM3 opened this issue Oct 11, 2022 · 6 comments
Open

Joi vs Yup comparison of core schemas #1800

HamzaM3 opened this issue Oct 11, 2022 · 6 comments

Comments

@HamzaM3
Copy link

HamzaM3 commented Oct 11, 2022

I have done a comparison of Joi and Yup core schemas. I have noticed a few things :

  • Yup.string accepts all types and people don't expect that at start. It would be cool if it would be stricter in the type testing and also allow for parsing the string (strict option is too strict)
  • Yup.number validates arrays with their first elements being a number. I think it's because of toString in the checking.
  • Yup.bool accepts 0 and 1, I find this to be unexpected and it's not mentioned in the documentation
  • There is no alternative type.

I think it would be cool if it was possible to add a way to be strict on the type testing while allowing parsing (maybe there is already).

Here's the comparison : https://github.com/HamzaM3/joi-yup-comparison

Thank you all for your work

@HamzaM3
Copy link
Author

HamzaM3 commented Oct 13, 2022

I have also found a bug with nonNullable as it is unavailable.

Yup version : ^0.32.11
Executed with node v16.0.0
My code:

const Yup = require('yup')
Yup.number().nonNullable() // throws nonNullable is not a function (it's value is undefined)
Yup.number().nullable().nonNullable() // throws nonNullable is not a function (it's value is undefined)

@jquense
Copy link
Owner

jquense commented Nov 2, 2022

does this bug exist in the v1?

@HamzaM3
Copy link
Author

HamzaM3 commented Nov 2, 2022

No not anymore, but the array to number bug is still there:

Yup.number().validate([3, 'str']) // validates 3

@jquense
Copy link
Owner

jquense commented Nov 3, 2022

Do you want to try and put up a PR to address that bug?

@HamzaM3
Copy link
Author

HamzaM3 commented Nov 3, 2022

Yes

@HamzaM3
Copy link
Author

HamzaM3 commented Nov 25, 2022

I finally had the time to take care of this, check out the pull request.

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

No branches or pull requests

2 participants