Improve error message for index signature on generic type when writing (#55906)

This commit is contained in:
Gabriela Araujo Britto
2023-10-18 17:43:43 -07:00
committed by GitHub
parent 413179867f
commit b1f5ef69e8
8 changed files with 117 additions and 5 deletions
+6 -1
View File
@@ -17845,7 +17845,12 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
if (indexInfo) {
if (accessFlags & AccessFlags.NoIndexSignatures && indexInfo.keyType !== numberType) {
if (accessExpression) {
error(accessExpression, Diagnostics.Type_0_cannot_be_used_to_index_type_1, typeToString(indexType), typeToString(originalObjectType));
if (accessFlags & AccessFlags.Writing) {
error(accessExpression, Diagnostics.Type_0_is_generic_and_can_only_be_indexed_for_reading, typeToString(originalObjectType));
}
else {
error(accessExpression, Diagnostics.Type_0_cannot_be_used_to_index_type_1, typeToString(indexType), typeToString(originalObjectType));
}
}
return undefined;
}
+4
View File
@@ -3699,6 +3699,10 @@
"category": "Error",
"code": 2861
},
"Type '{0}' is generic and can only be indexed for reading.": {
"category": "Error",
"code": 2862
},
"Import declaration '{0}' is using private name '{1}'.": {
"category": "Error",