mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-15 12:51:30 -05:00
Merge pull request #31542 from andrewbranch/bug/31481
Error when writing to rest element range of readonly tuple
This commit is contained in:
@@ -10106,6 +10106,7 @@ namespace ts {
|
||||
error(indexNode, Diagnostics.Property_0_does_not_exist_on_type_1, unescapeLeadingUnderscores(propName), typeToString(objectType));
|
||||
}
|
||||
}
|
||||
errorIfWritingToReadonlyIndex(getIndexInfoOfType(objectType, IndexKind.Number));
|
||||
return mapType(objectType, t => getRestTypeOfTupleType(<TupleTypeReference>t) || undefinedType);
|
||||
}
|
||||
}
|
||||
@@ -10127,13 +10128,7 @@ namespace ts {
|
||||
error(indexNode, Diagnostics.Type_0_cannot_be_used_as_an_index_type, typeToString(indexType));
|
||||
return indexInfo.type;
|
||||
}
|
||||
if (indexInfo.isReadonly && accessExpression && (isAssignmentTarget(accessExpression) || isDeleteTarget(accessExpression))) {
|
||||
if (accessExpression) {
|
||||
error(accessExpression, Diagnostics.Index_signature_in_type_0_only_permits_reading, typeToString(objectType));
|
||||
return indexInfo.type;
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
errorIfWritingToReadonlyIndex(indexInfo);
|
||||
return indexInfo.type;
|
||||
}
|
||||
if (indexType.flags & TypeFlags.Never) {
|
||||
@@ -10193,6 +10188,12 @@ namespace ts {
|
||||
return indexType;
|
||||
}
|
||||
return undefined;
|
||||
|
||||
function errorIfWritingToReadonlyIndex(indexInfo: IndexInfo | undefined): void {
|
||||
if (indexInfo && indexInfo.isReadonly && accessExpression && (isAssignmentTarget(accessExpression) || isDeleteTarget(accessExpression))) {
|
||||
error(accessExpression, Diagnostics.Index_signature_in_type_0_only_permits_reading, typeToString(objectType));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function getIndexNodeForAccessExpression(accessNode: ElementAccessExpression | IndexedAccessTypeNode | PropertyName | BindingName | SyntheticExpression) {
|
||||
|
||||
Reference in New Issue
Block a user