Skip to content

ErrorComponentProps#error incorrectly models the error type #4686

@michaelbull

Description

@michaelbull

Which project does this relate to?

Router

Describe the bug

The ErrorComponentProps type, that replaces the deprecated ErrorRouteProps, incorrectly models the error as an Error .

In our production app, our fetch behaviour does not throw an Error, but instead a detailed rich object that consumers can dig into.

In the simplest example, a route's loader could throw a primitive data type such as a string instead of an Error, however the props of the associated errorComponent (modelled as ErrorComponentProps) presume that the error will always be an Error.

Your Example Website or App

https://stackblitz.com/edit/github-gk2uhnxn?file=src%2Froutes%2Findex.tsx

Steps to Reproduce the Bug or Issue

Throw a non-Error data type in a loader, for example throw 'hello'.

Observe that the props of the loader's errorComponent incorrectly model the error prop as an Error type, even though we called throw with a typeof string.

Expected behavior

Preferably:

- export type ErrorComponentProps = {
-  error: Error
+ export type ErrorComponentProps<E> = {
+  error: E
  info?: { componentStack: string }
  reset: () => void
}

or at least:

- export type ErrorComponentProps = {
-  error: Error
+ export type ErrorComponentProps = {
+  error: unknown
  info?: { componentStack: string }
  reset: () => void
}

Screenshots or Videos

Image

Platform

@tanstack/[email protected]

Additional context

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions