BigInt support has been added on TypeScript 3.2; make sure your version is compatible.
But on top of that, you need to decide how BigInt will be supported on the context of your script - will you provide polyfills, or will you only run your script on environments that are guaranteed to have BigInt support?
This means you will need esnext as your build target (likely on tsconfig.json's target field), since BigInt is not compatible with previous ECMAScript versions.
If you do include a BigInt polyfill, you can use esnext.bigint as part of the lib field during transpilation. This adds the needed definitions to the process.
Typescript: using BigInt instead of number
Support for TC39 "BigInt: Arbitrary precision integers in JavaScript" proposal
How do I add a (number | bigint) to another (number | bigint), enforcing they they are of the same type?
What is the difference between 'bigint' (lowercase) and 'BigInt'?
Videos
BigInt support has been added on TypeScript 3.2; make sure your version is compatible.
But on top of that, you need to decide how BigInt will be supported on the context of your script - will you provide polyfills, or will you only run your script on environments that are guaranteed to have BigInt support?
This means you will need esnext as your build target (likely on tsconfig.json's target field), since BigInt is not compatible with previous ECMAScript versions.
If you do include a BigInt polyfill, you can use esnext.bigint as part of the lib field during transpilation. This adds the needed definitions to the process.
It works for me to add esnext.bigint in lib .
{
"compilerOptions": {
"lib": ["es6","esnext.bigint"]
}
}
I have two variables "a" and "b." Both can either be a "number" or a "bigint" but they will be of the same type. How do I assure TypeScript they will be the same type?