-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
BigInt support #25886
BigInt support #25886
Conversation
I removed the |
Also not sure how to avoid running the |
cool, a big work |
Hey @calebsander, thanks for the PR! However there are a couple of things that we should be up-front with you about:
I think @mhegazy and @sheetalkamat will be able to provide more detail here, but hopefully we can still leverage the work from both sides. |
It is actually only a ~1000 line change (600 of which are from the |
I reverted the LKG for now and removed references to |
Ah, another general remark: It looks like your parse handles it, but you need tests of bigint literals of all shapes and sizes with various configurations of numeric separators. I'd just add new entries to the numeric separator tests, myself, since those contain all kinds of literals with numeric separators in them. |
@mhegazy had mentioned that we should enable bigInt only under --experimentalBigInt compiler options flag. |
What features would you imagine being restricted without the flag? Just I'm not sure an experimental flag is necessary; no existing code should break with the change unless it is using the |
yes. basically any expression of type
The flag is not necessary for valid code generation. the flag is needed to inform the user that there is potential change in semantics that could happen in a future release. that is the same as decorators. |
Just chipping in from the sides. While the proposal is at Stage 3, by TC39's definition, there is a risk of implementation challenges which can effect the spec. For example, this behaviour isn't fully settled, while it unlikely to impact the TypeScript implementation, the flag is the only way to underline to users that it isn't fully baked yet and until it has an ES release there is a danger of how it gets aligned. It should be ES2019 but... For something like this, it feels fairly important to flag it until the proposal reaches Stage 4. |
Sure, that makes sense. I already added the flag. It will warn on any The Node.js 8 Travis job seems to have failed on the last build because npm couldn't resolve the |
I think we don't want to error in the keyword, just the literals. We don't want to error when the node .d.ts updates to use bigints in stats, for example - just on usages we won't be downleveling. Although @mhegazy has final say there. |
That sounds right to me. in general we should not error in an ambient context any ways.. |
I removed the error on the |
Hmm, it seems like the Travis build failure on Node 8 is due to |
Also need testcase for usage of bigint literals, type and BigInt() when esNext and when less than esNext with and without experimentalBigInt |
The |
Thank you @calebsander for this contribution. It should be available in tonight's nightly build. |
Hey @calebsander, I just updated to the Nightly from your own repo and now I am having TSLint issues, but it is compiling correctly. What were the flags to remove the warnings again? I think I noticed that you deleted them, or removed them. |
I'm not sure what is required for TSLint to work, but for |
"esnext.bigint", where would I find these? I do have my target already set at esnext, still not fixed on Atom or VS Code. So, I guess that I'm just missing the standard library declarations but, I didn't understand exactly where to put them. So to clarify, tsc does work. Its just TSLint that is showing that Typescript doesn't know what the BigInt features are. Not TSLint itself. Thanks. |
You need to set vscode to use your workspace version of typescript and install the |
This is just the declaration file that specifies |
Saviours, thank you. I hope your information will help the next person. |
Fixes #15096.
Additions:
bigint
primitive type, which is analogous to but distinct fromnumber
bigint
literals, e.g.123n
. Per the ECMAScript proposal, literals can be expressed in binary (0b
), octal (0o
), hex (0x
), or decimal formats.bigint
literals, likenumber
,string
, orboolean
literals, are valid types. The config optionexperimentalBigInt
must be set in order to usebigint
literals.bigint
values and returnbigint
resultstypeof
operator to include"bigint"
esnext.bigint
lib file, which defines theBigInt
,BigInt64Array
, andBigUint64Array
types, theBigInt
global, and the*int64*
methods ofDataView
parseBigInt
to test parsingbigint
literalsnumberVsBigIntOperations
to test that arithmetic operations accept and return the correct typeswarnExperimentalBigIntLiteral
to test that usingbigint
literals without the--experimentalBigInt
option throws an errorbigintWithLib
andbigintWithoutLib
to test theesnext.bigint
lib filebigintIndex
to assert thatbigint
values can't be used as indicesNotes:
bigint
is now a reserved word.The type of arithmetic operations with
any
types, e.g.<any>1 * <any>2
, was left asnumber
instead of changing it to the more accuratenumber | bigint
in order to maintain compatibility. Binary arithmetic operations are not allowed on operands ofnumber | bigint
type because it is possible that their runtime types conflict.Error messages referring to the type of arithmetic operands were updated, as was the type of
typeof
expressions, which required updating many reference baselines. Other than that, no existing tests' expected behaviors were changed. (See commits fd5771a and 73d0fbf.)bigint
is not allowed as an index type. Use astring
index instead and explicitly convert thebigint
to astring
.