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

Narrow Json error types #1637

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

thewilkybarkid
Copy link
Contributor

JSON.parse and JSON.stringify only throw SyntaxError and TypeError respectively, so we can narrow the types in the Json module.

There is one custom error in stringify, but this is better represented as a TypeError anyway.

@enricopolanski
Copy link

I like the proposal, I think though that we are missing a case?

JSON.stringify({x: 2n});
// TypeError: BigInt value can't be serialized in JSON

Should we handle both the TypeErrors messages rather than only cyclic references?

@thewilkybarkid
Copy link
Contributor Author

Having tried this out for a bit, these types are a bit problematic: TypeError and SyntaxError are just aliases of Error.

So, I'd probably say to create new error types, or just use Error (which is better than the original unknown).

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.

2 participants