You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Correct output: 9007199254740993
What JS actually prints: 9007199254740992
Some important things to note:
You cannot solve this by just passing a custom resolver to JSON.parse. Unfortunately, you need to replace JSON.parse entirely to be able to resolve large numbers without precision loss
There is no standard for how this case is handled. Should a library convert only numbers that exceed a certain value as bigint? That would cause the type of everything to become number | bigint everywhere which people may not want. In a lot of cases, the way to handle this ends up being context-specific
Given this, it may be best to just have an agreed-upon way to allow a user-provided JSON parser to use when resolving references
The text was updated successfully, but these errors were encountered:
Currently, this project relies on JSON.parse to load JSON files. However,
JSON.parse
is lossy on numbers larger thanNumber.MAX_SAFE_INTEGER
ex:
Correct output:
9007199254740993
What JS actually prints:
9007199254740992
Some important things to note:
JSON.parse
. Unfortunately, you need to replaceJSON.parse
entirely to be able to resolve large numbers without precision lossbigint
? That would cause the type of everything to becomenumber | bigint
everywhere which people may not want. In a lot of cases, the way to handle this ends up being context-specificGiven this, it may be best to just have an agreed-upon way to allow a user-provided JSON parser to use when resolving references
The text was updated successfully, but these errors were encountered: