Skip to content
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

feat: export proper ErrorResponse type #10811

Merged
merged 1 commit into from
Aug 23, 2023
Merged
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
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
Loading