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-errorThe code works as expected tho. I'm on this version:
"@tanstack/react-router": "^1.26.9"
8 Replies
absent-sapphire•10mo ago
you need to disable this lint rule
grumpy-cyanOP•10mo ago
I would rather avoid that and solve the problem instead.
Or open a ticket if there is no solution.
absent-sapphire•10mo 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•10mo ago
Does this work for you @cglacet ?
grumpy-cyanOP•10mo ago
That's nice, it seems to work, I had no idea you could shut a single error like that :). Thanks
equal-aqua•10mo ago
I had to use capital R for it to recognise the function, so "Redirect" instead of "redirect"
grumpy-cyanOP•10mo ago
Strangely it worked for my with the small "r"
On the other hand, my linter complains about the rule itself:
equal-aqua•10mo ago
https://github.com/typescript-eslint/typescript-eslint/pull/10221
typescript-eslint needs to be v8.13.0
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...