Cant use BigInt in TS project regardless of es2020

1.4k views Asked by At

I have simple TS project where this is my tsconfig.json

{
  "compilerOptions": {
    "target": "es2020",
    "lib": ["es2020"],
  }
}

And I have one file, script.ts with following code inside

BigInt(2);

Unfortunatelly, when I execute tsc script.ts, I receive this error: Cannot find name 'BigInt'. Do you need to change your target library? Try changing the 'lib' compiler option to 'es2020' or later.

Why is that happening? Isn't my library set to correct version?

1

There are 1 answers

1
Bane2000 On

BigInt is relativele new feature in Typescript, So in order to use it you have to specify target: esnext in your tsconfig.json

In your code you can create BigInt with n suffix, like this:

const bigIntNumber = 1n