0

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?

Weeedooo
  • 501
  • 8
  • 25
  • Is library supposed to be an array? (I'm not sure, but try this) Edit: looks like it is supposed to be an array – Samathingamajig Feb 11 '22 at 07:55
  • Per the duplicate question, try running just `tsc` (without `script.ts`). That makes sure `tsconfig.json` is actually read (when specifying a single source file, tsconfig.json is ignored). I've tried this locally and confirmed that it fixes the problem. – jmrk Feb 11 '22 at 12:22
  • Anyone coming here who is having this problem in Visual Studio, I found the solution to be to install the `Microsoft.TypeScript.MSBuild` NuGet package as per [here](https://www.typescriptlang.org/download). – Neo Aug 09 '22 at 18:07

1 Answers1

0

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
Bane2000
  • 187
  • 1
  • 9
  • `target: es2020` is enough (the advice to use `esnext` dates back to when ES2020 didn't exist yet), but `tsconfig.json` must actually be used. See the duplicate question. – jmrk Feb 11 '22 at 12:20