Avoid throwing non-Error values (throw-error)

May 28, 2021 ยท View on GitHub

This rule forbids throwing values that are neither Error nor DOMException instances.

Rule details

Examples of incorrect code for this rule:

throw "Kaboom!";
import { throwError } from "rxjs";
throwError("Kaboom!");
import { throwError } from "rxjs";
throwError(() => "Kaboom!");

Examples of correct code for this rule:

throw new Error("Kaboom!");
throw new RangeError("Kaboom!");
throw new DOMException("Kaboom!");
import { throwError } from "rxjs";
throwError(new Error("Kaboom!"));
import { throwError } from "rxjs";
throwError(() => new Error("Kaboom!"));

Options

This rule has no options.