mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00:00
Add readonly check to property access of index signature
Unfortunately, the checking code isn't reusable in a large chunk, so I copied it from `getPropertyTypeForIndexType`. It still might be better to extract the four lines to report the error into its own function.
This commit is contained in:
@@ -14599,9 +14599,13 @@ namespace ts {
|
||||
}
|
||||
const prop = getPropertyOfType(apparentType, right.escapedText);
|
||||
if (!prop) {
|
||||
const stringIndexType = getIndexTypeOfType(apparentType, IndexKind.String);
|
||||
if (stringIndexType) {
|
||||
return stringIndexType;
|
||||
const indexInfo = getIndexInfoOfType(apparentType, IndexKind.String);
|
||||
if (indexInfo && indexInfo.type) {
|
||||
if (indexInfo.isReadonly && (isAssignmentTarget(node) || isDeleteTarget(node))) {
|
||||
error(node, Diagnostics.Index_signature_in_type_0_only_permits_reading, typeToString(apparentType));
|
||||
return unknownType;
|
||||
}
|
||||
return indexInfo.type;
|
||||
}
|
||||
if (right.escapedText && !checkAndReportErrorForExtendingInterface(node)) {
|
||||
reportNonexistentProperty(right, type.flags & TypeFlags.TypeParameter && (type as TypeParameter).isThisType ? apparentType : type);
|
||||
|
||||
Reference in New Issue
Block a user