Offer per-member diagnostics for incorrectly implemented inherited members#21036
Merged
weswigham merged 3 commits intoJan 9, 2018
Merged
Conversation
|
Is it possible to have the name of the member and not just the type? |
mhegazy
reviewed
Jan 8, 2018
| "category": "Error", | ||
| "code": 2415 | ||
| }, | ||
| "Class member of type '{0}' is not assignable to base class member of type '{1}'.": { |
Contributor
There was a problem hiding this comment.
i would add the member name as well..
Contributor
There was a problem hiding this comment.
The error message before was helpful too. i wounder if we should make this an elaboration, e.g.:
Class '{0}' incorrectly extends base class '{1}'.
Member '{2}' of type '{3}' is not assignable to base class member of type '{3}'.
Member
Author
There was a problem hiding this comment.
With a little more in-person deliberation, I've changed it to the following:
Property 'bar' in type 'B' is not assignable to the same property in base type 'Base'.
Type 'string' is not assignable to type 'Base'.
a9995ce to
b563c1a
Compare
sandersn
approved these changes
Jan 8, 2018
| } | ||
|
|
||
| function issueMemberSpecificError(node: ClassLikeDeclaration, typeWithThis: Type, baseWithThis: Type, specificDiag: DiagnosticMessage, broadDiag: DiagnosticMessage) { | ||
| // iterate over all implemented properties and issue errors on each one which isn't compatible, ratehr than the class as a whole, if possible |
| } | ||
|
|
||
| function issueMemberSpecificError(node: ClassLikeDeclaration, typeWithThis: Type, baseWithThis: Type, broadDiag: DiagnosticMessage) { | ||
| // iterate over all implemented properties and issue errors on each one which isn't compatible, ratehr than the class as a whole, if possible |
| !!! error TS2416: Types of property 'n' are incompatible. | ||
| !!! error TS2416: Type 'string | DerivedInterface' is not assignable to type 'string | Base'. | ||
| !!! error TS2416: Type 'DerivedInterface' is not assignable to type 'string | Base'. | ||
| !!! error TS2416: Type 'DerivedInterface' is not assignable to type 'Base'. |
Member
There was a problem hiding this comment.
:(
Is this better than the old error?
Member
There was a problem hiding this comment.
After in-person discussion:
- It is the same as the old error, but at least the correct error is reported below.
- It's not that bad because we believe recursive-typed properties aren't that common, so there will not be many bogus errors showing up along with the real one.
mhegazy
approved these changes
Jan 9, 2018
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
If possible, this causes us to issue a diagnostic on each property which is not compatible with the base type, rather than just the class name. This should assist with identifying and correcting problem properties, since the reason for each property's mismatch will now be listed (if there are multiple which do not match).
Fixes #20980.