Skip to content

Commit a4495de

Browse files
authoredAug 23, 2023
Export proper ErrorResponse type (#10811)
1 parent 4cc8eec commit a4495de

File tree

9 files changed

+70
-50
lines changed

9 files changed

+70
-50
lines changed
 

‎.changeset/error-response-type.md

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
"react-router-dom-v5-compat": patch
3+
"react-router-native": patch
4+
"react-router-dom": patch
5+
"react-router": patch
6+
"@remix-run/router": patch
7+
---
8+
9+
Move the `@private` class export `ErrorResponse` to an `UNSAFE_ErrorResponse` export since it is an implementation detail and there should be no construction of `ErrorResponse` instances in userland. This frees us up to export a `type ErrorResponse` which correlates to an instance of the class via `InstanceType`. Userland code should only ever be using `ErrorResponse` as a type and should be type-narrowing via `isRouteErrorResponse`.

‎packages/react-router-dom-v5-compat/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ export type {
5353
BrowserRouterProps,
5454
DataRouteMatch,
5555
DataRouteObject,
56+
ErrorResponse,
5657
Fetcher,
5758
FetcherWithComponents,
5859
FormEncType,

‎packages/react-router-dom/index.tsx

+3-2
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ import {
4949
createHashHistory,
5050
joinPaths,
5151
stripBasename,
52-
ErrorResponse,
52+
UNSAFE_ErrorResponse as ErrorResponseImpl,
5353
UNSAFE_invariant as invariant,
5454
UNSAFE_warning as warning,
5555
} from "@remix-run/router";
@@ -92,6 +92,7 @@ export type {
9292
unstable_BlockerFunction,
9393
DataRouteMatch,
9494
DataRouteObject,
95+
ErrorResponse,
9596
Fetcher,
9697
Hash,
9798
IndexRouteObject,
@@ -273,7 +274,7 @@ function deserializeErrors(
273274
// Hey you! If you change this, please change the corresponding logic in
274275
// serializeErrors in react-router-dom/server.tsx :)
275276
if (val && val.__type === "RouteErrorResponse") {
276-
serialized[key] = new ErrorResponse(
277+
serialized[key] = new ErrorResponseImpl(
277278
val.status,
278279
val.statusText,
279280
val.data,

‎packages/react-router-native/index.tsx

+1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ export type {
2727
unstable_BlockerFunction,
2828
DataRouteMatch,
2929
DataRouteObject,
30+
ErrorResponse,
3031
Fetcher,
3132
Hash,
3233
IndexRouteObject,

‎packages/react-router/index.ts

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import type {
44
ActionFunctionArgs,
55
Blocker,
66
BlockerFunction,
7+
ErrorResponse,
78
Fetcher,
89
HydrationState,
910
InitialEntry,
@@ -127,6 +128,7 @@ export type {
127128
AwaitProps,
128129
DataRouteMatch,
129130
DataRouteObject,
131+
ErrorResponse,
130132
Fetcher,
131133
FutureConfig,
132134
Hash,

0 commit comments

Comments
 (0)
Please sign in to comment.