-
Notifications
You must be signed in to change notification settings - Fork 268
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
parse() should throw instead of returning undefined #123
Comments
It's unclear to me where this occurs. Line 94 in 40fdbd5
|
The handling of failure cases still seems sub-optimal to me. This is re: #184 (comment). TL;DR: Given that a major-version release is coming up anyway, I'd recommend to remedy this situation by being consistent: either always throwing, or always returning a specific error value. Additionally, there needs to be documentation in the README on how errors will be indicated to the caller. The TypeScript-specific examples there are unsafe since they don't check for Side note: Perhaps someone at Vercel could comment what they want to do? I'd be happy to contribute any required code/docs changes. |
It's especially confusing that it does throw when passed an empty string:
And then, despite the error message above, it's not thrown when val is not a valid number:
Could we have a fix to make these cases consistent? |
What's the reasoning behind
parse()
returningundefined
when given invalid input (e.g. '1 secnd')? In my opinion, an error will be much easier to detect and feels syntactically more appropriate – passing an invalid string is an erroneous usage of the function, after all.I'd totally be willing to draft a PR if there's agreement an error should be thrown.
The text was updated successfully, but these errors were encountered: