Back to Denoland

No New Symbol

lint/rules/no-new-symbol.md

latest468 B
Original Source

Disallows the use of new operators with built-in Symbols.

Symbols are created by being called as a function, but we sometimes call it with the new operator by mistake. This rule detects such wrong usage of the new operator.

Invalid:

typescript
const foo = new Symbol("foo");

Valid:

typescript
const foo = Symbol("foo");

function func(Symbol: typeof SomeClass) {
  // This `Symbol` is not built-in one
  const bar = new Symbol();
}