@@ -8845,7 +8845,15 @@ namespace ts {
8845
8845
error(accessExpression.argumentExpression, Diagnostics.Element_implicitly_has_an_any_type_because_index_expression_is_not_of_type_number);
8846
8846
}
8847
8847
else {
8848
- error(accessExpression, Diagnostics.Element_implicitly_has_an_any_type_because_type_0_has_no_index_signature, typeToString(objectType));
8848
+ let suggestion: string | undefined;
8849
+ if (propName !== undefined && (suggestion = getSuggestionForNonexistentProperty(propName as string, objectType))) {
8850
+ if (suggestion !== undefined) {
8851
+ error(accessExpression.argumentExpression, Diagnostics.Property_0_does_not_exist_on_type_1_Did_you_mean_2, propName as string, typeToString(objectType), suggestion);
8852
+ }
8853
+ }
8854
+ else {
8855
+ error(accessExpression, Diagnostics.Element_implicitly_has_an_any_type_because_type_0_has_no_index_signature, typeToString(objectType));
8856
+ }
8849
8857
}
8850
8858
}
8851
8859
return anyType;
@@ -17367,14 +17375,21 @@ namespace ts {
17367
17375
errorInfo = chainDiagnosticMessages(errorInfo, Diagnostics.Property_0_does_not_exist_on_type_1_Did_you_mean_2, declarationNameToString(propNode), typeToString(containingType), suggestion);
17368
17376
}
17369
17377
else {
17370
- errorInfo = chainDiagnosticMessages(errorInfo, Diagnostics.Property_0_does_not_exist_on_type_1, declarationNameToString(propNode), typeToString(containingType));
17378
+ const suggestion = getSuggestionForNonexistentProperty(propNode, containingType);
17379
+ if (suggestion !== undefined) {
17380
+ errorInfo = chainDiagnosticMessages(errorInfo, Diagnostics.Property_0_does_not_exist_on_type_1_Did_you_mean_2, declarationNameToString(propNode), typeToString(containingType), suggestion);
17381
+ }
17382
+ else {
17383
+ errorInfo = chainDiagnosticMessages(errorInfo, Diagnostics.Property_0_does_not_exist_on_type_1, declarationNameToString(propNode), typeToString(containingType));
17384
+ }
17371
17385
}
17372
17386
}
17387
+
17373
17388
diagnostics.add(createDiagnosticForNodeFromMessageChain(propNode, errorInfo));
17374
17389
}
17375
17390
17376
- function getSuggestionForNonexistentProperty(node : Identifier, containingType: Type): string | undefined {
17377
- const suggestion = getSpellingSuggestionForName(idText(node ), getPropertiesOfType(containingType), SymbolFlags.Value);
17391
+ function getSuggestionForNonexistentProperty(name : Identifier | string , containingType: Type): string | undefined {
17392
+ const suggestion = getSpellingSuggestionForName(isString(name) ? name : idText(name ), getPropertiesOfType(containingType), SymbolFlags.Value);
17378
17393
return suggestion && symbolName(suggestion);
17379
17394
}
17380
17395
0 commit comments