-
Notifications
You must be signed in to change notification settings - Fork 12.5k
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
Support for TC39 "BigInt: Arbitrary precision integers in JavaScript" proposal #15096
Comments
🚲:house: |
Looks like this may be landing in Babel soon: |
Initial (WIP) babel PR for this: babel/babel#6015 |
Looks like the BigInt proposal has also hit stage 3 (tc39/proposal-bigint@1b4c7e6). Would be awesome to see TypeScript support. |
Personally looking forward to getting the feature available - only concern is the ducktape syntax, my hope is that typescript can help keep the syntax clean. |
@RyanCavanaugh @mhegazy @andy-ms Or does it need to land in Edge first? |
BigInt is implemented in V8, means we will have it in chrome and V8 soon |
Node 10.4.0 ships with V8 6.7, a flag is no longer needed to be able to use big integers. |
seems have a plan to support it on 3.0 |
@Kingwl Yes, I see it on the roadmap for 3.0 as you said 👍 For others viewing this issue, the roadmap can be found on the wiki here: https://github.com/Microsoft/TypeScript/wiki/Roadmap#30-july-2018 |
Fantastic! Looks like support just landed in Babel too: babel/babel#8006 |
@tarcieri That does not do the transformation right? So |
i'm not sure that will we add the transformer (maybe polyfill) as @FranklinYu said |
Does it mean that keyof type will be changed again to include bigint? |
While TypeScript 3.1 is still in the works, here is a placeholder. Put this in a type BigInt = number
declare const BigInt: typeof Number This allows you to use |
@calebsander but |
TypeScript does not generally provide polyfills to add support for features to old platforms. The compiler performs simple syntactic desugaring, e.g. to implement |
There's work underway to support it in babel if you need support on older platforms: babel/proposals#2 |
I thought it may be feasible for TypeScript compiler to recognize and transpile |
PR #25886 was merged! Use |
@calebsander - thanks! I'm using your PR successfully in https://github.com/no2chem/bigint-buffer, but it seems that a lot of tooling (webpack, typedoc) will remain broken, so the workaround you suggested in #15096 (comment) helps a lot in these cases (for example, I include bigint.d.ts when using typedoc to build documentation). |
Thanks for this! |
What about indexer type ? [1,2,3][1n] It means that indexer type now has to be allowed as: string | number | bigint |
|
@novemberborn You have a more general suggestion. type Indexer = number | string | bigint | ({ toString(): string|number }) |
Sorry, I was suggesting that there are other types that work in JavaScript, but for sensible reasons are not supported in TypeScript. |
BigInt is allowed to be index in ES, so there is no question here. |
We considered this in #25886 and decided against adding |
Thanks. |
It is probably a bit off-topic but I searched some time for a possibility to use BigInt today and came across this project: https://github.com/GoogleChromeLabs/jsbi It has the same API and there is a babel-transform plugin to remove it eventually. |
Integrating JSBI was already discussed in #28756 |
Merge pull requested |
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:
Implicit conversions to/from numbers and integers and expressions with mixed operands are expressly disallowed:
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
anduint64
types in addition to e.g. aninteger
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.The text was updated successfully, but these errors were encountered: