Replies: 1 comment 1 reply
-
I've opened #2248 to improve this. In the meantime, you can set the types in your project. Place this in a import '@tanstack/react-router'
declare module '@tanstack/react-router' {
// https://github.com/TanStack/router/pull/2248
export function notFound(options: { throw: true }): never
export function notFound(options: { throw?: false }): NotFoundError
} As an alternative, you can wrap it in a local implementationimport { notFound } from '@tanstack/react-router'
export default function throwNotFound(): never {
notFound({ throw: true })
// notFound will always throw, so this line will never be reached,
// but TypeScript doesn't know that, so we need to throw here to make it happy
throw new Error('notFound() did not throw')
} |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
According to the documentation
notFound()
can be returned or thrown:Since the return value of
notFound()
is not an instance ofError
my ESLint setup is complaining about throwing it. That’s why I thought I could try the alternative of returning it. Unfortunately this changes also the return type ofuseLoaderData()
, which is suddenly a union type ofNotFoundError | MyLoadedData
. Shouldn’t this type beeing removed automatically, because the router is already taking care of the not-found scenario and my component shouldn’t even get rendered souseLoaderData()
won’t be executed?.Beta Was this translation helpful? Give feedback.
All reactions