fix(41227): change message about incorrect property access with possible replacement with static access (#41275)

This commit is contained in:
Oleksandr T
2020-11-18 22:50:32 +02:00
committed by GitHub
parent d3abd35428
commit 9bbbe5c0c7
20 changed files with 97 additions and 69 deletions

View File

@@ -13910,7 +13910,8 @@ namespace ts {
}
else if (noImplicitAny && !compilerOptions.suppressImplicitAnyIndexErrors && !suppressNoImplicitAnyError) {
if (propName !== undefined && typeHasStaticProperty(propName, objectType)) {
error(accessExpression, Diagnostics.Property_0_is_a_static_member_of_type_1, propName as string, typeToString(objectType));
const typeName = typeToString(objectType);
error(accessExpression, Diagnostics.Property_0_does_not_exist_on_type_1_Did_you_mean_to_access_the_static_member_2_instead, propName as string, typeName, typeName + "[" + getTextOfNode(accessExpression.argumentExpression) + "]");
}
else if (getIndexTypeOfType(objectType, IndexKind.Number)) {
error(accessExpression.argumentExpression, Diagnostics.Element_implicitly_has_an_any_type_because_index_expression_is_not_of_type_number);
@@ -26038,7 +26039,9 @@ namespace ts {
}
}
if (typeHasStaticProperty(propNode.escapedText, containingType)) {
errorInfo = chainDiagnosticMessages(errorInfo, Diagnostics.Property_0_is_a_static_member_of_type_1, declarationNameToString(propNode), typeToString(containingType));
const propName = declarationNameToString(propNode);
const typeName = typeToString(containingType);
errorInfo = chainDiagnosticMessages(errorInfo, Diagnostics.Property_0_does_not_exist_on_type_1_Did_you_mean_to_access_the_static_member_2_instead, propName, typeName, typeName + "." + propName);
}
else {
const promisedType = getPromisedTypeOfPromise(containingType);

View File

@@ -2293,7 +2293,7 @@
"category": "Error",
"code": 2575
},
"Property '{0}' is a static member of type '{1}'.": {
"Property '{0}' does not exist on type '{1}'. Did you mean to access the static member '{2}' instead?": {
"category": "Error",
"code": 2576
},