mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-10 10:58:20 -05:00
improve error message for extending interface
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user