Skip to content

fix(router-core): update ErrorRouteComponent to support generic error type #4727

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions packages/react-router/src/route.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ import type { LinkComponentRoute } from './link'
declare module '@tanstack/router-core' {
export interface UpdatableRouteOptionsExtensions {
component?: RouteComponent
errorComponent?: false | null | ErrorRouteComponent
errorComponent?: false | null | ErrorRouteComponent<any>

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason we wouldn't add the TError generic?

export interface UpdatableRouteOptionsExtensions<TError = Error> {
    errorComponent?: false | null | ErrorRouteComponent<TError>

Copy link
Contributor Author

@leesb971204 leesb971204 Jul 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason we wouldn't add the TError generic?

export interface UpdatableRouteOptionsExtensions<TError = Error> {
    errorComponent?: false | null | ErrorRouteComponent<TError>

If we make this change, wouldn’t it cause a type error in the errorComponent?
스크린샷 2025-07-21 오후 9 18 39

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@michaelbull

Do you have any additional ideas regarding this?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not really sure to be honest. Its unclear to me why that would cause a compiler error, and I explicitly use code-based routing (createRoute) not file based. I suspect you would have to chase the generic error type onto UpdatableRouteOptionsExtensions as well, but now I'm starting to second guess following this through.

I would defer to @schiller-manuel.

notFoundComponent?: NotFoundRouteComponent
pendingComponent?: RouteComponent
}
Expand Down Expand Up @@ -555,7 +555,9 @@ export type AsyncRouteComponent<TProps> = RouteTypes<TProps>['component'] & {

export type RouteComponent = AsyncRouteComponent<{}>

export type ErrorRouteComponent = AsyncRouteComponent<ErrorComponentProps>
export type ErrorRouteComponent<TError = Error> = AsyncRouteComponent<
ErrorComponentProps<TError>
>

export type NotFoundRouteComponent = RouteTypes<NotFoundRouteProps>['component']

Expand Down
6 changes: 4 additions & 2 deletions packages/solid-router/src/route.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ import type { LinkComponentRoute } from './link'
declare module '@tanstack/router-core' {
export interface UpdatableRouteOptionsExtensions {
component?: RouteComponent
errorComponent?: false | null | ErrorRouteComponent
errorComponent?: false | null | ErrorRouteComponent<any>
notFoundComponent?: NotFoundRouteComponent
pendingComponent?: RouteComponent
}
Expand Down Expand Up @@ -499,7 +499,9 @@ export type AsyncRouteComponent<TProps> = RouteTypes<TProps>['component'] & {

export type RouteComponent = AsyncRouteComponent<{}>

export type ErrorRouteComponent = AsyncRouteComponent<ErrorComponentProps>
export type ErrorRouteComponent<TError = Error> = AsyncRouteComponent<
ErrorComponentProps<TError>
>

export type NotFoundRouteComponent = RouteTypes<NotFoundRouteProps>['component']

Expand Down