Improve inter-operability between BigInt and regular Numbers

Right now, when you perform math between BigInts and regular numbers, it creates TypeErrors. While this makes sense for numbers with values after the decimal point, it does not make sense for Integers. For the Integer case, they should simply be cast to BigInts instead.

Right now, this is how addition works:

const a = BigInt(8) + 7
Uncaught TypeError: Cannot mix BigInt and other types, use explicit conversions

This is how I think it should work:

const a = BigInt(8) + 7;
const b = a===BigInt(15)
//b evaluates to true

That sort of implicit promotion was intentionally disallowed when BigInts were being designed, because BigInts aren’t a superset of Number. We wanted to avoid an accidental promotion, which then later caused an error (possibly a logic error, rather than a JS exception) because you were now doing division on a BigInt but intended the result to be fractional.

1 Like