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');