mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00:00
Merge pull request #9180 from HerringtonDarkholme/interface
[Fix #9004] Improve error message for extending interface
This commit is contained in:
+28
-2
@@ -853,7 +853,8 @@ namespace ts {
|
||||
|
||||
if (!result) {
|
||||
if (nameNotFoundMessage) {
|
||||
if (!checkAndReportErrorForMissingPrefix(errorLocation, name, nameArg)) {
|
||||
if (!checkAndReportErrorForMissingPrefix(errorLocation, name, nameArg) &&
|
||||
!checkAndReportErrorForExtendingInterface(errorLocation)) {
|
||||
error(errorLocation, nameNotFoundMessage, typeof nameArg === "string" ? nameArg : declarationNameToString(nameArg));
|
||||
}
|
||||
}
|
||||
@@ -937,6 +938,31 @@ namespace ts {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
function checkAndReportErrorForExtendingInterface(errorLocation: Node): boolean {
|
||||
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 (!parentClassExpression) {
|
||||
return false;
|
||||
}
|
||||
const expression = (<ExpressionWithTypeArguments>parentClassExpression).expression;
|
||||
if (resolveEntityName(expression, SymbolFlags.Interface, /*ignoreErrors*/ true)) {
|
||||
error(errorLocation, Diagnostics.Cannot_extend_an_interface_0_Did_you_mean_implements, getTextOfNode(expression));
|
||||
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
|
||||
@@ -10137,7 +10163,7 @@ namespace ts {
|
||||
}
|
||||
const prop = getPropertyOfType(apparentType, right.text);
|
||||
if (!prop) {
|
||||
if (right.text) {
|
||||
if (right.text && !checkAndReportErrorForExtendingInterface(node)) {
|
||||
error(right, Diagnostics.Property_0_does_not_exist_on_type_1, declarationNameToString(right), typeToString(type.flags & TypeFlags.ThisType ? apparentType : type));
|
||||
}
|
||||
return unknownType;
|
||||
|
||||
@@ -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