TypeScript and Large Number
Don't use the Number type to store or calculate numbers that could exceed TypeScript's safe integer range of -9007199254740991 to 9007199254740991.
* If the number only needs to be transported or presented, consider using a String instead.
* Integers will be natively supported in TypeScript 3.1.
* The big-integer library can be used for a pure JS/TS workaround.https://www.npmjs.com/package/big-integer
* The bignum library can be used when performance is needed (uses OpenSSL) https://www.npmjs.com/package/bignum
var obj = JSON.parse('{ "id1": "-4653387195933842958", "id2": "-4653387195933842959" }');
console.log(obj.id1); //-4653387195933842958
console.log(obj.id2); //-4653387195933842959
var obj = JSON.parse('{ "id1": -4653387195933842958, "id2": -4653387195933842959 }');
console.log(obj.id1); //-4653387195933843000
console.log(obj.id2); //-4653387195933843000
-9, 007, 199, 254, 740, 991
-4, 653, 387, 195, 933, 842, 959
JSON.parse will always have this issue.
References:
https://www.webtoolkitonline.com/javascript-tester.html
Don't use the Number type to store or calculate numbers that could exceed TypeScript's safe integer range of -9007199254740991 to 9007199254740991.
* If the number only needs to be transported or presented, consider using a String instead.
* Integers will be natively supported in TypeScript 3.1.
* The big-integer library can be used for a pure JS/TS workaround.https://www.npmjs.com/package/big-integer
* The bignum library can be used when performance is needed (uses OpenSSL) https://www.npmjs.com/package/bignum
var obj = JSON.parse('{ "id1": "-4653387195933842958", "id2": "-4653387195933842959" }');
console.log(obj.id1); //-4653387195933842958
console.log(obj.id2); //-4653387195933842959
var obj = JSON.parse('{ "id1": -4653387195933842958, "id2": -4653387195933842959 }');
console.log(obj.id1); //-4653387195933843000
console.log(obj.id2); //-4653387195933843000
-9, 007, 199, 254, 740, 991
-4, 653, 387, 195, 933, 842, 959
JSON.parse will always have this issue.
References:
https://www.webtoolkitonline.com/javascript-tester.html