Skip to content

Support for TC39 "BigInt: Arbitrary precision integers in JavaScript" proposal #15096

Closed
@tarcieri

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 between 0 and 2**width-1
  • Integer.asIntN(width, Integer): Wrap an Integer between -2**(width-1) and 2**(width-1)-1
  • Integer.parseInt(string[, radix]): Analogous to Number.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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

Labels

CommittedThe team has roadmapped this issueES NextNew featurers for ECMAScript (a.k.a. ESNext)SuggestionAn idea for TypeScript

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions