Support for TC39 "BigInt: Arbitrary precision integers in JavaScript" proposal #15096
Description
The ECMAScript Technical Committee 39 has put forward a concrete proposal for adding integers to JavaScript:
https://tc39.github.io/proposal-bigint/
The proposal adds a new syntax for integer literals:
42n // This is an integer literal
Implicit conversions to/from numbers and integers and expressions with mixed operands are expressly disallowed:
42n + 1 // Throws TypeError
Type constructors are provided that wrap at specified widths:
Integer.asUintN(width, Integer)
: Wrap an Integer between0
and2**width-1
Integer.asIntN(width, Integer)
: Wrap an Integer between-2**(width-1)
and2**(width-1)-1
Integer.parseInt(string[, radix])
: Analogous toNumber.parseInt
, to parse an Integer from a String in any base.
Though not stated in the spec, these constructors should theoretically hint to the VM when it's possible to use a native 64-bit integer type instead of a bignum, and could therefore possibly be used by TypeScript to implement int64
and uint64
types in addition to e.g. an integer
type of arbitrary precision.
I know people have been asking for integers for quite some time (e.g. #195, #4639), but have been held back by lack of native support of an integer type in JavaScript itself. Now it seems this proposal is stage 2 (scratch that, stage 3!) and has multi-browser vendor backing, so perhaps the prerequisites are finally in place to make integers happen.
Activity