-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Add Javascript declarations to index constraint check error reporting #15586
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
Add Javascript declarations to index constraint check error reporting #15586
Conversation
Now Javascript-style declarations like `this.foo = "bar"` are handled correctly.
@@ -20233,7 +20233,10 @@ namespace ts { | |||
// perform property check if property or indexer is declared in 'type' | |||
// this allows to rule out cases when both property and indexer are inherited from the base class | |||
let errorNode: Node; | |||
if (propDeclaration && (propDeclaration.name.kind === SyntaxKind.ComputedPropertyName || prop.parent === containingType.symbol)) { | |||
if (propDeclaration && | |||
(getSpecialPropertyAssignmentKind(propDeclaration as BinaryExpression) === SpecialPropertyAssignmentKind.ThisProperty || |
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.
consider moving this to the end of the check
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.
It actually needs to come first because JS-style assignments should not hit the computed property check. It won't be very expensive because most declarations are not in javascript files and even there, most declarations are not JS-style assignment declarations.
@sandersn, Please port this to release-2.3 |
I'll look into normalising use of |
It's merged into 2.3 now. |
if (propDeclaration && (propDeclaration.name.kind === SyntaxKind.ComputedPropertyName || prop.parent === containingType.symbol)) { | ||
if (propDeclaration && | ||
(getSpecialPropertyAssignmentKind(propDeclaration as BinaryExpression) === SpecialPropertyAssignmentKind.ThisProperty || | ||
propDeclaration.name.kind === SyntaxKind.ComputedPropertyName || |
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.
This may crash if propDeclaration.name is undefined
.
see #15681
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.
Will be fixed in #15594
Now Javascript-style declarations like
this.foo = "bar"
are handledcorrectly and errors will be reported on the declaration correctly. Previously the code would check the computed property name case and crash because Javascript-style declarations have no
name
property.Fixes #15525