From 38962eea82f9bbb07c9657d0b7e2bb64d292c1a6 Mon Sep 17 00:00:00 2001 From: Herrington Darkholme Date: Fri, 17 Jun 2016 10:22:56 +0800 Subject: [PATCH] use resolveEntityName to find interface --- src/compiler/checker.ts | 35 ++++++++++++++++------------------- 1 file changed, 16 insertions(+), 19 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index b0484fc890c..6081770f62e 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -939,29 +939,26 @@ namespace ts { function checkAndReportErrorForExtendingInterface(errorLocation: Node): boolean { - const container = getContainingClass(errorLocation); - const heritageClause = getAncestor(errorLocation, SyntaxKind.HeritageClause); - if (!container || !heritageClause || heritageClause.token !== SyntaxKind.ExtendsKeyword) { + let parentClassExpression = errorLocation; + while (parentClassExpression) { + const kind = parentClassExpression.kind; + if (kind === SyntaxKind.Identifier || kind === SyntaxKind.PropertyAccessExpression) { + parentClassExpression = parentClassExpression.parent; + continue; + } + if (kind === SyntaxKind.ExpressionWithTypeArguments) { + break; + } return false; } - if (errorLocation.kind === SyntaxKind.Identifier) { - const name = (errorLocation).text; - const interfaceOrModule = resolveName( - errorLocation, name, - SymbolFlags.Interface | SymbolFlags.HasExports, - /*errorMessage*/ undefined, /*nameArg*/ undefined) - if (!interfaceOrModule) { - return false; - } - if (interfaceOrModule.flags & SymbolFlags.Interface) { - error(errorLocation, Diagnostics.Cannot_extend_an_interface_0_Did_you_mean_implements, name); - return true; - } + if (!parentClassExpression) { + return false; } - else if (errorLocation.kind === SyntaxKind.PropertyAccessExpression) { - // todo + const expression = (parentClassExpression).expression; + if (resolveEntityName(expression, SymbolFlags.Interface, true)) { + error(errorLocation, Diagnostics.Cannot_extend_an_interface_0_Did_you_mean_implements, getTextOfNode(expression)); + return true; } - return false; }