feat: export proper ErrorResponse
type
#10811
Merged
+70
−50
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This handles the callout in remix-run/remix#7238 which has come up a few times in discord as well.
We always wanted
class ErrorResponse
to be an implementation detail since it serves no runtime purpose in userland. We naively thoughtisRouteErrorResponse
's type narrowing would be sufficient, and is in the simple case:However, this is limited since you can't build abstractions around these errors:
The class was always marked
@private
and wasn't ever intended to be used, so this PR moves the class to anUNSAFE_ErrorResponseImpl
export. Because it was always marked "private", I don't consider this a breaking change.That frees up the
ErrorResponse
name so we can export a type of an instance of the class, which properly excludes the private properties:Then we can export this
ErrorResponse
type out through@remix-run/react
as well.Main changes are in
utils.ts
- the rest is just bubbling the name changes out and exporting the new type out through the dependent packages