@@ -10723,8 +10723,9 @@ namespace ts {
10723
10723
10724
10724
const sourceCount = getParameterCount(source);
10725
10725
const sourceRestType = getNonArrayRestType(source);
10726
- const targetRestType = sourceRestType ? getNonArrayRestType(target) : undefined;
10727
- if (sourceRestType && !(targetRestType && sourceCount === targetCount)) {
10726
+ const targetRestType = getNonArrayRestType(target);
10727
+ if (sourceRestType && targetRestType && sourceCount !== targetCount) {
10728
+ // We're not able to relate misaliged complex rest parameters
10728
10729
return Ternary.False;
10729
10730
}
10730
10731
@@ -10750,11 +10751,12 @@ namespace ts {
10750
10751
}
10751
10752
}
10752
10753
10753
- const paramCount = Math.max(sourceCount, targetCount);
10754
- const lastIndex = paramCount - 1;
10754
+ const paramCount = sourceRestType || targetRestType ? Math.min(sourceCount, targetCount) : Math.max(sourceCount, targetCount);
10755
+ const restIndex = sourceRestType || targetRestType ? paramCount - 1 : -1;
10756
+
10755
10757
for (let i = 0; i < paramCount; i++) {
10756
- const sourceType = i === lastIndex && sourceRestType || getTypeAtPosition(source, i);
10757
- const targetType = i === lastIndex && targetRestType || getTypeAtPosition(target, i);
10758
+ const sourceType = i === restIndex ? getRestTypeAtPosition(source, i) : getTypeAtPosition(source, i);
10759
+ const targetType = i === restIndex ? getRestTypeAtPosition(target, i) : getTypeAtPosition(target, i);
10758
10760
// In order to ensure that any generic type Foo<T> is at least co-variant with respect to T no matter
10759
10761
// how Foo uses T, we need to relate parameters bi-variantly (given that parameters are input positions,
10760
10762
// they naturally relate only contra-variantly). However, if the source and target parameters both have
@@ -13049,11 +13051,9 @@ namespace ts {
13049
13051
const targetCount = getParameterCount(target);
13050
13052
const sourceRestType = getEffectiveRestType(source);
13051
13053
const targetRestType = getEffectiveRestType(target);
13052
- const maxCount = sourceRestType && targetRestType ? Math.max(sourceCount, targetCount ) :
13054
+ const paramCount = targetRestType ? Math.min(targetCount - 1, sourceCount ) :
13053
13055
sourceRestType ? targetCount :
13054
- targetRestType ? sourceCount :
13055
13056
Math.min(sourceCount, targetCount);
13056
- const paramCount = targetRestType ? Math.min(targetCount - 1, maxCount) : maxCount;
13057
13057
for (let i = 0; i < paramCount; i++) {
13058
13058
callback(getTypeAtPosition(source, i), getTypeAtPosition(target, i));
13059
13059
}
0 commit comments