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.
This commit is contained in:
Nathan Shively-Sanders 2016-02-26 13:46:36 -08:00
parent 17b7c3eee1
commit 28640c8ae1

View File

@ -2607,7 +2607,8 @@ namespace ts {
// Return the inferred type for a binding element
function getTypeForBindingElement(declaration: BindingElement): Type {
const pattern = <BindingPattern>declaration.parent;
const parentType = getTypeForBindingElementParent(<VariableLikeDeclaration>pattern.parent);
const parent = <VariableLikeDeclaration>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 = <InterfaceType>getDeclaredTypeOfSymbol(getParentOfSymbol(prop));
if (left.kind === SyntaxKind.SuperKeyword) {
const errorNode = node.kind === SyntaxKind.PropertyAccessExpression ?
(<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 ?
(<PropertyAccessExpression | VariableDeclaration>node).name :
(<QualifiedName>node).right;
// TS 1.0 spec (April 2014): 4.8.2