throw-new-error
UnreleasedConfiguration
rslint.config.ts
Rule Details
Require new when creating an error.
Calling an error constructor without new still produces an error object, but
it is easy to mistake for an ordinary function call, and it breaks as soon as
the class is subclassed or its prototype is relied upon.
Although the rule is named for throw, it applies to every call expression, so
a bare call such as const error = Error() is reported too.
Examples of incorrect code for this rule:
Examples of correct code for this rule:
Calls that new cannot be applied to are left alone — an optional-chained call
such as Error?.() or lib?.Error(), a computed access such as
lib["Error"](), and a decorator call such as @RegisterServiceError().