Skip to content

Commit

Permalink
Export proper ErrorResponse type
Browse files Browse the repository at this point in the history
  • Loading branch information
brophdawg11 committed Aug 23, 2023
1 parent 4cc8eec commit 356f2a5
Show file tree
Hide file tree
Showing 9 changed files with 70 additions and 50 deletions.
9 changes: 9 additions & 0 deletions .changeset/error-response-type.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
"react-router-dom-v5-compat": patch
"react-router-native": patch
"react-router-dom": patch
"react-router": patch
"@remix-run/router": patch
---

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`.
1 change: 1 addition & 0 deletions packages/react-router-dom-v5-compat/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ export type {
BrowserRouterProps,
DataRouteMatch,
DataRouteObject,
ErrorResponse,
Fetcher,
FetcherWithComponents,
FormEncType,
Expand Down
5 changes: 3 additions & 2 deletions packages/react-router-dom/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ import {
createHashHistory,
joinPaths,
stripBasename,
ErrorResponse,
UNSAFE_ErrorResponse as ErrorResponseImpl,
UNSAFE_invariant as invariant,
UNSAFE_warning as warning,
} from "@remix-run/router";
Expand Down Expand Up @@ -92,6 +92,7 @@ export type {
unstable_BlockerFunction,
DataRouteMatch,
DataRouteObject,
ErrorResponse,
Fetcher,
Hash,
IndexRouteObject,
Expand Down Expand Up @@ -273,7 +274,7 @@ function deserializeErrors(
// Hey you! If you change this, please change the corresponding logic in
// serializeErrors in react-router-dom/server.tsx :)
if (val && val.__type === "RouteErrorResponse") {
serialized[key] = new ErrorResponse(
serialized[key] = new ErrorResponseImpl(
val.status,
val.statusText,
val.data,
Expand Down
1 change: 1 addition & 0 deletions packages/react-router-native/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export type {
unstable_BlockerFunction,
DataRouteMatch,
DataRouteObject,
ErrorResponse,
Fetcher,
Hash,
IndexRouteObject,
Expand Down
2 changes: 2 additions & 0 deletions packages/react-router/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import type {
ActionFunctionArgs,
Blocker,
BlockerFunction,
ErrorResponse,
Fetcher,
HydrationState,
InitialEntry,
Expand Down Expand Up @@ -127,6 +128,7 @@ export type {
AwaitProps,
DataRouteMatch,
DataRouteObject,
ErrorResponse,
Fetcher,
FutureConfig,
Hash,
Expand Down

0 comments on commit 356f2a5

Please sign in to comment.