Skip to content

Latest commit

 

History

History
38 lines (26 loc) · 829 Bytes

throw-new-error.md

File metadata and controls

38 lines (26 loc) · 829 Bytes

Require new when creating an error

💼 This rule is enabled in the ✅ recommended config.

🔧 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.

Fail

const error = Error('unicorn');
throw TypeError('unicorn');
throw lib.TypeError('unicorn');

Pass

const error = new Error('unicorn');
throw new TypeError('unicorn');
throw new lib.TypeError('unicorn');