throw-error
Disallow throwing or rejecting values that are not Error-like.
โ ๏ธ This rule requires type information to run.
Targeted pattern scopeโ
This rule checks:
ThrowStatementarguments,Promise.reject(...)calls,reject(...)calls insidenew Promise((resolve, reject) => ...)executors.
What this rule reportsโ
This rule reports values that are not Error-like when thrown or used as Promise rejection values.
It allows:
ErrorandDOMExceptionvalues,- values that could be
anyorunknown(to avoid unsafe assumptions during static analysis).
Why this rule existsโ
Throwing primitives or arbitrary objects makes error handling inconsistent and often forces fragile downstream narrowing logic. Enforcing Error-like values improves reliability and observability.
โ Incorrectโ
throw "kaboom";
Promise.reject("kaboom");
new Promise((resolve, reject) => reject("kaboom"));
โ Correctโ
throw new Error("kaboom");
throw new DOMException("kaboom");
Promise.reject(new Error("kaboom"));
new Promise((resolve, reject) => reject(new Error("kaboom")));
Behavior and migration notesโ
This rule has no options.
Additional examplesโ
declare const maybeUnknown: unknown;
throw maybeUnknown;
// โ
allowed (unknown is intentionally permitted)
const payload = { code: "E_FAIL" };
throw payload;
// โ reported (not Error-like)
ESLint flat config exampleโ
import etcMisc from "eslint-plugin-etc-misc";
export default [
{
plugins: { "etc-misc": etcMisc },
rules: {
"etc-misc/throw-error": "error",
},
},
];
When not to use itโ
Disable this rule if your codebase intentionally uses non-Error throw/reject values and has established handling utilities for that pattern.
Package documentationโ
Rule catalog ID: R074
Further readingโ
Adoption resourcesโ
- Start at warning level in CI, then move to error after cleanup.
- Use focused codemods/autofix batches per package or directory.