'Cant use BigInt in TS project regardless of es2020 [duplicate]

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?



Solution 1:[1]

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

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Bane2000