'Cannot find name 'BigInt'. Do you need to change your target library? Try changing the 'lib' compiler option to 'es2020' or later

I'm trying to compile my typescript file using tsc index.ts command, but it's showing me this error Cannot find the name 'BigInt'. Do you need to change your target library? Try changing the 'lib' compiler option to 'es2020' or later.

index.ts file code:

// string type
let a: string = "hello world";

// number type
let b: number = 5;

// boolean type
let c: boolean = true;

// null type
let d: null = null;

// bigint
let f: bigint = BigInt(100);

// symbol type
let g: symbol = Symbol("name");

tsconfig.json file:

{
  "compilerOptions": {
    "module": "commonjs",
    "strict": true,
    "noImplicitAny": false,
    "strictNullChecks": true,
    "removeComments": true
  },
  "files": ["./index.ts"]
}

Anyone please help me with this.



Solution 1:[1]

Do you need to change your target library? Try changing the 'lib' compiler option to 'es2020' or later.

This means you should add lib like so:

{
  "compilerOptions": {
    "module": "commonjs",
    "strict": true,
    "noImplicitAny": false,
    "strictNullChecks": true,
    "removeComments": true,
    "lib": ["ES2020"]
  },
  "files": ["./index.ts"]
}

Inside lib you would put all of the environment type definitions you need. For example, if I wanted to use ESNext and ESNext's async iterables, I would use:

"lib": ["esnext", "esnext.asynciterable"]

Strings given to lib are case-insensitive so ESNEXT would be the same as esnext or ESNext.

Links to docs

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 hittingonme