-
-
Notifications
You must be signed in to change notification settings - Fork 10.3k
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
Specify ErrorResponse
as interface to provide obvious contract
#10876
Conversation
🦋 Changeset detectedLatest commit: 6a0543f The changes in this PR will be included in the next version bump. This PR includes changesets to release 5 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Hi @sgrishchenko, Welcome, and thank you for contributing to React Router! Before we consider your pull request, we ask that you sign our Contributor License Agreement (CLA). We require this only once. You may review the CLA and sign it by adding your name to contributors.yml. Once the CLA is signed, the If you have already signed the CLA and received this response in error, or if you have any questions, please contact us at hello@remix.run. Thanks! - The Remix team |
Thank you for signing the Contributor License Agreement. Let's get this merged! 🥳 |
Can you explain the use-case for which you are trying to create an |
The first point is that with my changes, you don't need 3-line comment about interface/implementation pattern. Now code is self-documented. The second point: in the comment I removed there was the statement:
And your example perfectly demonstrates that with
And the third point: with the current declaration, I don't see the public contract of |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you - the unit test is a great use-case for why we should make the change. I was just concerned that this was something being used incorrectly in app-code 👍
you don't need 3-line comment about interface/implementation pattern. Now code is self-documented.
Eh - "Self documenting code" is a buzzword I've seen abused too much over the years. Code describes "what"/"how", comments describe "why". Removing this comment is detrimental because we lose the reason for why we keep the interface and class separate in the first place.
@sgrishchenko Do you mind rebasing this and repointing it to |
Ok, probably I'm wrong with the point that the comment is unnecessary anymore. I returned the comment back. |
Oh, you mean |
packages/router/utils.ts
Outdated
@@ -1533,11 +1533,21 @@ export const redirectDocument: RedirectFunction = (url, init) => { | |||
return response; | |||
}; | |||
|
|||
export interface ErrorResponse { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we keep this as a type
to avoid changing the semantics to interface
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, we can, but from my point of view it exposes the public API, so it is exactly an interface semantically, or am I missing something? Maybe you want to avoid interface merging?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, we prefer type
over interface
unless we need the ability for end users to augment the interface
, which we shouldn't in this case
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
🤖 Hello there, We just published version Thanks! |
🤖 Hello there, We just published version Thanks! |
There is problem in current declaration of
ErrorResponse
: the private field leaks to the public contract. SoErrorResponse
type behaves very strange on usage (see playground).I propose to simplify the declaration of
ErrorResponse
and declare it's public interface obviously.