mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00:00
Improve error message for index signature on generic type when writing (#55906)
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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",
|
||||
|
||||
Reference in New Issue
Block a user