-
Notifications
You must be signed in to change notification settings - Fork 12.8k
JSON.parse is not supposed to return any #26993
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
Comments
Maybe unknown is more correct |
Assuming no
But how useful would that be? I think most code wouldn't want a structure like this, unless you wrote a library that was specifically for making modifications on the structure of any JSON. In most realistic use cases, you're going to want to cast the return of |
This is exactly correct |
As mentioned in #26188 and several other places, returning any from To be clear: To handle all this we could have two signatures for
Some may be frustrated by the compiler telling them that they really don't know the type returned. That's understandable: all of us had to unlearn bad habits when we went from JavaScript to TypeScript. All that said, I'd REALLY appreciate Yes this would be a breaking change. But a welcome one. It could also be behind a flag like the change to catch so that it could be introduced in a minor version. As an aside, the project |
TypeScript Version: 3.1.0-dev.20180828
Search Terms: JSON parse type any
Code
Expected behavior:
JSON parse spec expect it to return
object | number | string | boolean | null
Actual behavior:
JSON parse implementation at
lib/lib.es5.d.ts
expect it to return anyThe text was updated successfully, but these errors were encountered: