noInvalidNewBuiltin (since v1.3.0)
Diagnostic Category: lint/correctness/noInvalidNewBuiltin
Source: no-new-native-nonconstructor
Disallow new
operators with global non-constructor functions.
Some global functions cannot be called using the new operator and
will throw a TypeError
if you attempt to do so. These functions are:
Examples
Section titled ExamplesInvalid
Section titled Invalidlet foo = new Symbol('foo');
correctness/noInvalidNewBuiltin.js:1:11 lint/correctness/noInvalidNewBuiltin FIXABLE ━━━━━━━━━━━━━
✖ Symbol cannot be called as a constructor.
> 1 │ let foo = new Symbol('foo');
│ ^^^^^^^^^^^^^^^^^
2 │
ℹ Calling Symbol with the new operator throws a TypeError.
ℹ Unsafe fix: Remove new.
1 │ let·foo·=·new·Symbol('foo');
│ ----
let bar = new BigInt(9007199254740991);
correctness/noInvalidNewBuiltin.js:1:11 lint/correctness/noInvalidNewBuiltin FIXABLE ━━━━━━━━━━━━━
✖ BigInt cannot be called as a constructor.
> 1 │ let bar = new BigInt(9007199254740991);
│ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2 │
ℹ Calling BigInt with the new operator throws a TypeError.
ℹ Unsafe fix: Remove new.
1 │ let·bar·=·new·BigInt(9007199254740991);
│ ----
Valid
Section titled Validlet foo = Symbol('foo');
function baz(Symbol) { const qux = new Symbol("baz");}
let bar = BigInt(9007199254740991);
function quux(BigInt) { const corge = new BigInt(9007199254740991);}