-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Open
Labels
bugSomething isn't workingSomething isn't workingpackage: eslint-pluginIssues related to @typescript-eslint/eslint-pluginIssues related to @typescript-eslint/eslint-plugintriageWaiting for team members to take a lookWaiting for team members to take a look
Description
Before You File a Bug Report Please Confirm You Have Done The Following...
- I have tried restarting my IDE and the issue persists.
- I have updated to the latest version of the packages.
- I have searched for related issues and found none that matched my issue.
- I have read the FAQ and my problem is not listed.
Playground Link
Repro Code
function f1<T>() {
let err: Promise<T>;
throw err;
}
function f2<T1, T2>() {
let err: Promise<T1> | Promise<T2>;
throw err;
}
ESLint Config
{
"rules": {
"@typescript-eslint/only-throw-error": [
"error",
{
"allow": [
"Promise"
]
}
]
}
}
tsconfig
Expected Result
The only-throw-error warning should not be triggered by f1()
or f2()
. When the "allow" option is Promise
, I should be able to throw an error of Promise<A> | Promise<B>
.
Actual Result
The "only-throw-error" rule triggers when a union is thrown.
Expected an error object to be thrown. 8:9 - 8:12

Additional Info
My actual use-case is with TanStack Router, which allows users to throw redirect(...)
(this throws a Redirect
type). I have a function that can return various redirects (which are later thrown):
function getRedirect(a, b) {
if (a) return redirect(...); // returns Redirect<A>
else return redirect(...); // returns Redirect<B>
}
This returns a union of Redirect<A> | Redirect<B>
. The following code triggers and ESLint error because it is trying to throw a union type.
throw getRedirect(a, b);
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't workingpackage: eslint-pluginIssues related to @typescript-eslint/eslint-pluginIssues related to @typescript-eslint/eslint-plugintriageWaiting for team members to take a lookWaiting for team members to take a look