From 28640c8ae16b59ebee58973e8b5eb0a876a65768 Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders Date: Fri, 26 Feb 2016 13:46:36 -0800 Subject: [PATCH] `checkClassPropertyAccess` in `getTypeForBindingElement` This is probably the wrong place (a get- function rather than a check- function), but it's a starting point since it passes all tests. --- src/compiler/checker.ts | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index ebc8d16e6e2..38de2bc6a44 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -2607,7 +2607,8 @@ namespace ts { // Return the inferred type for a binding element function getTypeForBindingElement(declaration: BindingElement): Type { const pattern = declaration.parent; - const parentType = getTypeForBindingElementParent(pattern.parent); + const parent = pattern.parent; + const parentType = getTypeForBindingElementParent(parent); // If parent has the unknown (error) type, then so does this binding element if (parentType === unknownType) { return unknownType; @@ -2642,6 +2643,11 @@ namespace ts { error(name, Diagnostics.Type_0_has_no_property_1_and_no_string_index_signature, typeToString(parentType), declarationNameToString(name)); return unknownType; } + + const property = getPropertyOfType(parentType, text); + if (parent && parent.initializer && property && getParentOfSymbol(property)) { + checkClassPropertyAccess(parent, parent.initializer, parentType, property); + } } else { // This elementType will be used if the specific property corresponding to this index is not @@ -8971,13 +8977,14 @@ namespace ts { * @param type The type of left. * @param prop The symbol for the right hand side of the property access. */ - function checkClassPropertyAccess(node: PropertyAccessExpression | QualifiedName, left: Expression | QualifiedName, type: Type, prop: Symbol): boolean { + function checkClassPropertyAccess(node: PropertyAccessExpression | QualifiedName | VariableLikeDeclaration, left: Expression | QualifiedName, type: Type, prop: Symbol): boolean { const flags = getDeclarationFlagsFromSymbol(prop); const declaringClass = getDeclaredTypeOfSymbol(getParentOfSymbol(prop)); if (left.kind === SyntaxKind.SuperKeyword) { - const errorNode = node.kind === SyntaxKind.PropertyAccessExpression ? - (node).name : + // TODO: Move this out and use it in the rest of the code + const errorNode = node.kind === SyntaxKind.PropertyAccessExpression || node.kind === SyntaxKind.VariableDeclaration ? + (node).name : (node).right; // TS 1.0 spec (April 2014): 4.8.2