mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-06-10 18:04:18 -05:00
Ensure rest type for source parameter is readonly in relations (#53258)
This commit is contained in:
@@ -19850,7 +19850,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
|
||||
const restIndex = sourceRestType || targetRestType ? paramCount - 1 : -1;
|
||||
|
||||
for (let i = 0; i < paramCount; i++) {
|
||||
const sourceType = i === restIndex ? getRestTypeAtPosition(source, i) : tryGetTypeAtPosition(source, i);
|
||||
const sourceType = i === restIndex ? getRestTypeAtPosition(source, i, /*readonly*/ true) : tryGetTypeAtPosition(source, i);
|
||||
const targetType = i === restIndex ? getRestTypeAtPosition(target, i) : tryGetTypeAtPosition(target, i);
|
||||
if (sourceType && targetType) {
|
||||
// In order to ensure that any generic type Foo<T> is at least co-variant with respect to T no matter
|
||||
@@ -34656,12 +34656,12 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
function getRestTypeAtPosition(source: Signature, pos: number): Type {
|
||||
function getRestTypeAtPosition(source: Signature, pos: number, readonly = false): Type {
|
||||
const parameterCount = getParameterCount(source);
|
||||
const minArgumentCount = getMinArgumentCount(source);
|
||||
const restType = getEffectiveRestType(source);
|
||||
if (restType && pos >= parameterCount - 1) {
|
||||
return pos === parameterCount - 1 ? restType : createArrayType(getIndexedAccessType(restType, numberType));
|
||||
return pos === parameterCount - 1 ? restType : createArrayType(getIndexedAccessType(restType, numberType), readonly);
|
||||
}
|
||||
const types = [];
|
||||
const flags = [];
|
||||
@@ -34680,7 +34680,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
|
||||
names.push(name);
|
||||
}
|
||||
}
|
||||
return createTupleType(types, flags, /*readonly*/ false, length(names) === length(types) ? names : undefined);
|
||||
return createTupleType(types, flags, readonly, length(names) === length(types) ? names : undefined);
|
||||
}
|
||||
|
||||
// Return the number of parameters in a signature. The rest parameter, if present, counts as one
|
||||
|
||||
Reference in New Issue
Block a user