π Require new when creating an error.
πΌ This rule is enabled in the following configs: β
recommended, βοΈ unopinionated.
π§ This rule is automatically fixable by the --fix CLI option.
While it's possible to create a new error without using the new keyword, it's better to be explicit.
This rule identifies error constructors by names such as Error, TypeError, and CustomError. Calls whose results are immediately called are ignored because they may be factories.
When TypeScript type information is available, calls that return a function or class are also ignored, including factories whose result is stored for later use.
// β
const error = Error('unicorn');
// β
const error = new Error('unicorn');// β
throw TypeError('unicorn');
// β
throw new TypeError('unicorn');// β
throw lib.TypeError('unicorn');
// β
throw new lib.TypeError('unicorn');