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
Require numbers to be finite by default? #1560
Comments
a. I'd argue that Imagine The explicit version b. Most users use |
I agree that it's unexpected, and I think that regardless of how finiteness is handled,
I think it's common for people to want an empty string, and rare for people to want
That also means that this would mainly affect people doing math and validating the results. It wouldn't make a difference for most users, so no harm in adding the restriction. I also want to note that in practice I've seen errors caused by external JSON where numbers larger than I guess this comes down to whether Thanks for your thoughts, much appreciated! |
It looks like there is actually precedent for validating semantic meaning rather than javascript type. Invalid dates, which are similar to > z.date().parse(new Date('invalid'))
Uncaught:
[
{
"code": "invalid_date",
"path": [],
"message": "Invalid date"
}
] It seems like doing the same for numbers would improve library consistency. |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
Not stale |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
Not stale |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
not stale |
#1546 (closed #512) added a new way of specifying that numbers should be finite but didn't address the question of whether numbers should be required to be finite by default.
Would a pull request to make numbers finite by default be accepted? It would have to be a breaking change, but I think it would improve consistency and help prevent errors for most zod users.
From the previous issue:
The text was updated successfully, but these errors were encountered: