Skip to content

newNativeNonConstructors

Disallows using new with global non-constructor functions like Symbol and BigInt.

✅ This rule is included in the ts javascript presets.

The global Symbol and BigInt functions are not constructors and will throw a TypeError when called with the new keyword. These functions should be called directly without new to create their respective values.

const
const symbol: any
symbol
= new
var Symbol: SymbolConstructor
Symbol
("description");
const
const bigNumber: any
bigNumber
= new
var BigInt: BigIntConstructor
BigInt
(42);
function
function create(): any
create
() {
return new
var BigInt: BigIntConstructor
BigInt
(100);
}

This rule is not configurable.

If you have globally overridden BigInt and/or Symbol with classes that are meant to be used as constructors, you may want to disable this rule. However, overriding these names is generally not recommended as it can cause confusion with the global functions.

Made with ❤️‍🔥 around the world by the Flint team and contributors.