T
TanStack10mo ago
grumpy-cyan

TS error in the beforeLoad example (throwing the wrong type)

Hello, I have a TS error with this example : https://tanstack.com/router/v1/docs/framework/react/guide/authenticated-routes#redirecting The error is located at throw redirect({ to: '/login' }); The error is :
Expected an error object to be thrown.eslint@typescript-eslint/only-throw-error
The code works as expected tho. I'm on this version: "@tanstack/react-router": "^1.26.9"
8 Replies
absent-sapphire
absent-sapphire10mo ago
you need to disable this lint rule
grumpy-cyan
grumpy-cyanOP10mo ago
I would rather avoid that and solve the problem instead. Or open a ticket if there is no solution.
absent-sapphire
absent-sapphire10mo ago
there is no problem to solve really. we use throw for control flow. redirect is not an error but still is thrown.
equal-aqua
equal-aqua10mo ago
Does this work for you @cglacet ?
rules: {
'@typescript-eslint/only-throw-error': [
'error',
{
allow: [
{
from: 'package',
name: ['redirect'],
package: '@tanstack/react-router',
},
],
},
],
},
rules: {
'@typescript-eslint/only-throw-error': [
'error',
{
allow: [
{
from: 'package',
name: ['redirect'],
package: '@tanstack/react-router',
},
],
},
],
},
grumpy-cyan
grumpy-cyanOP10mo ago
That's nice, it seems to work, I had no idea you could shut a single error like that :). Thanks
equal-aqua
equal-aqua10mo ago
I had to use capital R for it to recognise the function, so "Redirect" instead of "redirect"
grumpy-cyan
grumpy-cyanOP10mo ago
Strangely it worked for my with the small "r" On the other hand, my linter complains about the rule itself:
Configuration for rule "@typescript-eslint/only-throw-error" is invalid:
Value {"allow":[{"from":"package","name":["redirect"],"package":"@tanstack/react-router"}]} should NOT have additional properties.
Configuration for rule "@typescript-eslint/only-throw-error" is invalid:
Value {"allow":[{"from":"package","name":["redirect"],"package":"@tanstack/react-router"}]} should NOT have additional properties.
equal-aqua
equal-aqua10mo ago
GitHub
feat(eslint-plugin): [only-throw-error] add allow option by yeonjua...
PR Checklist Addresses an existing open issue: fixes Bug: [only-throw-error] add an 'allow' option using the TypeOrValueSpecifier shape #9525 That issue was marked as accepting p...

Did you find this page helpful?