diff --git a/.changeset/error-response-type.md b/.changeset/error-response-type.md new file mode 100644 index 0000000000..47f3a99961 --- /dev/null +++ b/.changeset/error-response-type.md @@ -0,0 +1,5 @@ +--- +"@remix-run/router": patch +--- + +Fix `ErrorResponse` type to avoid leaking internal field diff --git a/contributors.yml b/contributors.yml index 83e3037b26..36102cc500 100644 --- a/contributors.yml +++ b/contributors.yml @@ -238,3 +238,4 @@ - yionr - yuleicul - zheng-chuang +- sgrishchenko diff --git a/packages/router/utils.ts b/packages/router/utils.ts index c4ffa68f7b..5b50f6d761 100644 --- a/packages/router/utils.ts +++ b/packages/router/utils.ts @@ -1533,11 +1533,21 @@ export const redirectDocument: RedirectFunction = (url, init) => { return response; }; +export type ErrorResponse = { + status: number; + statusText: string; + data: any; +}; + /** * @private * Utility class we use to hold auto-unwrapped 4xx/5xx Response bodies + * + * We don't export the class for public use since it's an implementation + * detail, but we export the interface above so folks can build their own + * abstractions around instances via isRouteErrorResponse() */ -export class ErrorResponseImpl { +export class ErrorResponseImpl implements ErrorResponse { status: number; statusText: string; data: any; @@ -1562,11 +1572,6 @@ export class ErrorResponseImpl { } } -// We don't want the class exported since usage of it at runtime is an -// implementation detail, but we do want to export the shape so folks can -// build their own abstractions around instances via isRouteErrorResponse() -export type ErrorResponse = InstanceType; - /** * Check if the given error is an ErrorResponse generated from a 4xx/5xx * Response thrown from an action/loader