@@ -20837,8 +20837,8 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
20837
20837
const restIndex = sourceRestType || targetRestType ? paramCount - 1 : -1;
20838
20838
20839
20839
for (let i = 0; i < paramCount; i++) {
20840
- const sourceType = i === restIndex ? getRestTypeAtPosition (source, i) : tryGetTypeAtPosition(source, i);
20841
- const targetType = i === restIndex ? getRestTypeAtPosition (target, i) : tryGetTypeAtPosition(target, i);
20840
+ const sourceType = i === restIndex ? getRestOrAnyTypeAtPosition (source, i) : tryGetTypeAtPosition(source, i);
20841
+ const targetType = i === restIndex ? getRestOrAnyTypeAtPosition (target, i) : tryGetTypeAtPosition(target, i);
20842
20842
if (sourceType && targetType) {
20843
20843
// In order to ensure that any generic type Foo<T> is at least co-variant with respect to T no matter
20844
20844
// how Foo uses T, we need to relate parameters bi-variantly (given that parameters are input positions,
@@ -36464,6 +36464,15 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
36464
36464
return createTupleType(types, flags, readonly, names);
36465
36465
}
36466
36466
36467
+ // Return the rest type at the given position, transforming `any[]` into just `any`. We do this because
36468
+ // in signatures we want `any[]` in a rest position to be compatible with anything, but `any[]` isn't
36469
+ // assignable to tuple types with required elements.
36470
+ function getRestOrAnyTypeAtPosition(source: Signature, pos: number): Type {
36471
+ const restType = getRestTypeAtPosition(source, pos);
36472
+ const elementType = restType && getElementTypeOfArrayType(restType);
36473
+ return elementType && isTypeAny(elementType) ? anyType : restType;
36474
+ }
36475
+
36467
36476
// Return the number of parameters in a signature. The rest parameter, if present, counts as one
36468
36477
// parameter. For example, the parameter count of (x: number, y: number, ...z: string[]) is 3 and
36469
36478
// the parameter count of (x: number, ...args: [number, ...string[], boolean])) is also 3. In the
@@ -36527,7 +36536,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
36527
36536
if (signatureHasRestParameter(signature)) {
36528
36537
const restType = getTypeOfSymbol(signature.parameters[signature.parameters.length - 1]);
36529
36538
if (!isTupleType(restType)) {
36530
- return restType;
36539
+ return isTypeAny(restType) ? anyArrayType : restType;
36531
36540
}
36532
36541
if (restType.target.hasRestElement) {
36533
36542
return sliceTupleType(restType, restType.target.fixedLength);
0 commit comments