Skip to content

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