#error is of type unknown

1 messages · Page 1 of 1 (latest)

cobalt galleon
#

I'm trying to use useRouteError and I'm getting an error message when trying to access properties of the error object.

const error = useRouteError();

return (
  <div>
    {/* 'error' is of type 'unknown'.ts(18046) */}
    <p>{error.statusText || error.message}</p>
  </div>
);

Any ideas on how to resolve this? Or should I just ignore the TypeScript error?

mild snow
#

“Unknown” may actually be correct typescript behavior for a caught “error”?

You can check with “error instanceof Error” and if true typescript will let you access eg error.message

mild snow