diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index a2fe0065983..d5f89bee8bf 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -852,7 +852,8 @@ namespace ts { if (!result) { if (nameNotFoundMessage) { - if (!checkAndReportErrorForMissingPrefix(errorLocation, name, nameArg)) { + if (!checkAndReportErrorForMissingPrefix(errorLocation, name, nameArg) && + !checkAndReportErrorForExtendingInterface(errorLocation, name)) { error(errorLocation, nameNotFoundMessage, typeof nameArg === "string" ? nameArg : declarationNameToString(nameArg)); } } @@ -936,6 +937,25 @@ namespace ts { return false; } + + function checkAndReportErrorForExtendingInterface(errorLocation: Node, name: string): boolean { + if (!errorLocation || errorLocation.kind !== SyntaxKind.Identifier || + !errorLocation.parent || !errorLocation.parent.parent || + errorLocation.parent.parent.kind !== SyntaxKind.HeritageClause) { + return false; + } + const heritageClause = errorLocation.parent.parent; + if (heritageClause.token !== SyntaxKind.ExtendsKeyword) { + return false; + } + const enclosingScope = heritageClause.parent.parent.locals; + if (enclosingScope && getSymbol(enclosingScope, name, SymbolFlags.Interface)) { + error(errorLocation, Diagnostics.Cannot_extend_an_interface_0_Did_you_mean_implements, name); + return true; + } + return false; + } + function checkResolvedBlockScopedVariable(result: Symbol, errorLocation: Node): void { Debug.assert((result.flags & SymbolFlags.BlockScopedVariable) !== 0); // Block-scoped variables cannot be used before their definition diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index b78c342481f..30a4e1575e5 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -1935,6 +1935,10 @@ "category": "Error", "code": 2688 }, + "Cannot extend an interface '{0}'. Did you mean 'implements'?": { + "category": "Error", + "code": 2689 + }, "Import declaration '{0}' is using private name '{1}'.": { "category": "Error", "code": 4000