Why is this an issue?
new operator with
BigInt will throw a
TypeError because they are not
intended to be used as constructors.
This is different from the other primitive types, such as string, number or boolean, where it was possible to call global
Number as functions that return primitive types, but also use them as constructors with the
new operator to create wrapper
objects. This confusing double behavior is not implemented for
BigInt types that were introduced later in the
This behavior would be especially problematic for symbols that have reference identity and already behave like objects in some way. For example,
they are garbage collectable and therefore can be used as keys in WeakMap and WeakSet objects.
let foo = new Symbol('abc'); // Noncompliant: TypeError: Symbol is not a constructor
let bar = new BigInt(123); // Noncompliant: TypeError: BigInt is not a constructor
To fix the code remove the
let foo = Symbol('abc');
let bar = BigInt(123);
BigInt type to be recognized correctly, the environment should be
es2020 or higher.