-
Notifications
You must be signed in to change notification settings - Fork 12
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
Fix int64 overflow issue to due precision issues in Typescript with large numbers #253
Fix int64 overflow issue to due precision issues in Typescript with large numbers #253
Conversation
@@ -85,7 +85,7 @@ | |||
"lodash.pickby": "^4.6.0", | |||
"openapi3-ts": "^2.0.2", | |||
"postman-collection": "^4.1.2", | |||
"tslib": "^2.3.1", | |||
"tslib": "^2.6.2", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Number.MAX_SAFE_INTEGER and Number.MIN_SAFE_INTEGER are not available on tslib v2.3.1 so we need to update
@daniel-white Hi! Could someone from your team please take a look at this PR? Thanks! |
Heyo! I'll take a look at the PR soon |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ideally, we'd switch these values over to bigints, but that'd be somewhat troublesome to implement and would require changes across many repos and libraries.
I'm fine with this change since at the very least the values are now well within the range.
🎉 This PR is included in version 6.0.2 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Currently,
MAX_INT_64
is set to2 ** 63 - 1
, andMIN_INT_64
is set to0 - 2 ** 63
insrc/oas/transformers/schema/keywords/format.ts
. The TypeScript compiler evaluates these, respectively, to 9223372036854776000 and -9223372036854776000.Motivation and Context
These values are outside the range of int64 and result in bugs in clients such as Prism that use this library (e.g. stoplightio/prism#1992).
The reasoning behind this erroneous calculation is explained here: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/MAX_SAFE_INTEGER. Essentially, we are overflowing the capacity of JavaScript's Number type, and beyond Number.MAX_SAFE_INTEGER + 1 (9007199254740992), the IEEE-754 floating-point format can no longer represent every consecutive integer (see: https://stackoverflow.com/questions/1379934/large-numbers-erroneously-rounded-in-javascript).
Description
Thus, instead of setting
MAX_INT_64
to2 ** 63 - 1
, andMIN_INT_64
to0 - 2 ** 63
, we set them to TypeScript's built-in Number.MAX_SAFE_INTEGER and Number.MIN_SAFE_INTEGER instead.How Has This Been Tested?
Update local tests including screenshot tests.
Types of changes
Checklist