@@ -2607,7 +2607,8 @@ namespace ts {
2607
2607
// Return the inferred type for a binding element
2608
2608
function getTypeForBindingElement(declaration: BindingElement): Type {
2609
2609
const pattern = <BindingPattern>declaration.parent;
2610
- const parentType = getTypeForBindingElementParent(<VariableLikeDeclaration>pattern.parent);
2610
+ const parent = <VariableLikeDeclaration>pattern.parent;
2611
+ const parentType = getTypeForBindingElementParent(parent);
2611
2612
// If parent has the unknown (error) type, then so does this binding element
2612
2613
if (parentType === unknownType) {
2613
2614
return unknownType;
@@ -2642,6 +2643,11 @@ namespace ts {
2642
2643
error(name, Diagnostics.Type_0_has_no_property_1_and_no_string_index_signature, typeToString(parentType), declarationNameToString(name));
2643
2644
return unknownType;
2644
2645
}
2646
+
2647
+ const property = getPropertyOfType(parentType, text);
2648
+ if (parent && parent.initializer && property && getParentOfSymbol(property)) {
2649
+ checkClassPropertyAccess(parent, parent.initializer, parentType, property);
2650
+ }
2645
2651
}
2646
2652
else {
2647
2653
// This elementType will be used if the specific property corresponding to this index is not
@@ -8971,13 +8977,14 @@ namespace ts {
8971
8977
* @param type The type of left.
8972
8978
* @param prop The symbol for the right hand side of the property access.
8973
8979
*/
8974
- function checkClassPropertyAccess(node: PropertyAccessExpression | QualifiedName, left: Expression | QualifiedName, type: Type, prop: Symbol): boolean {
8980
+ function checkClassPropertyAccess(node: PropertyAccessExpression | QualifiedName | VariableLikeDeclaration , left: Expression | QualifiedName, type: Type, prop: Symbol): boolean {
8975
8981
const flags = getDeclarationFlagsFromSymbol(prop);
8976
8982
const declaringClass = <InterfaceType>getDeclaredTypeOfSymbol(getParentOfSymbol(prop));
8977
8983
8978
8984
if (left.kind === SyntaxKind.SuperKeyword) {
8979
- const errorNode = node.kind === SyntaxKind.PropertyAccessExpression ?
8980
- (<PropertyAccessExpression>node).name :
8985
+ // TODO: Move this out and use it in the rest of the code
8986
+ const errorNode = node.kind === SyntaxKind.PropertyAccessExpression || node.kind === SyntaxKind.VariableDeclaration ?
8987
+ (<PropertyAccessExpression | VariableDeclaration>node).name :
8981
8988
(<QualifiedName>node).right;
8982
8989
8983
8990
// TS 1.0 spec (April 2014): 4.8.2
0 commit comments