improve error message for extending interface

This commit is contained in:
Herrington Darkholme
2016-06-15 20:54:56 +08:00
parent 38c89af6b2
commit 386fa3e1f6
2 changed files with 25 additions and 1 deletions

View File

@@ -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 = <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

View File

@@ -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