throw-new-error
March 27, 2026 ยท View on GitHub
๐ 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.
Examples
// โ
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');