@@ -17279,7 +17279,11 @@ namespace ts {
17279
17279
result &= signaturesRelatedTo(source, type, SignatureKind.Construct, /*reportStructuralErrors*/ false);
17280
17280
if (result) {
17281
17281
result &= indexTypesRelatedTo(source, type, IndexKind.String, /*sourceIsPrimitive*/ false, /*reportStructuralErrors*/ false, IntersectionState.None);
17282
- if (result) {
17282
+ // Comparing numeric index types when both `source` and `type` are tuples is unnecessary as the
17283
+ // element types should be sufficiently covered by `propertiesRelatedTo`. It also causes problems
17284
+ // with index type assignability as the types for the excluded discriminants are still included
17285
+ // in the index type.
17286
+ if (result && !(isTupleType(source) && isTupleType(type))) {
17283
17287
result &= indexTypesRelatedTo(source, type, IndexKind.Number, /*sourceIsPrimitive*/ false, /*reportStructuralErrors*/ false, IntersectionState.None);
17284
17288
}
17285
17289
}
@@ -17504,6 +17508,7 @@ namespace ts {
17504
17508
for (let i = 0; i < maxArity; i++) {
17505
17509
const targetFlags = i < targetArity ? target.target.elementFlags[i] : targetRestFlag;
17506
17510
const sourceFlags = isTupleType(source) && i < sourceArity ? source.target.elementFlags[i] : sourceRestFlag;
17511
+ let canExcludeDiscriminants = !!excludedProperties;
17507
17512
if (sourceFlags && targetFlags) {
17508
17513
if (targetFlags & ElementFlags.Variadic && !(sourceFlags & ElementFlags.Variadic) ||
17509
17514
(sourceFlags & ElementFlags.Variadic && !(targetFlags & ElementFlags.Variable))) {
@@ -17520,6 +17525,15 @@ namespace ts {
17520
17525
return Ternary.False;
17521
17526
}
17522
17527
}
17528
+ // We can only exclude discriminant properties if we have not yet encountered a variable-length element.
17529
+ if (canExcludeDiscriminants) {
17530
+ if (sourceFlags & ElementFlags.Variable || targetFlags & ElementFlags.Variable) {
17531
+ canExcludeDiscriminants = false;
17532
+ }
17533
+ if (canExcludeDiscriminants && excludedProperties?.has(("" + i) as __String)) {
17534
+ continue;
17535
+ }
17536
+ }
17523
17537
const sourceType = getTypeArguments(source)[Math.min(i, sourceArity - 1)];
17524
17538
const targetType = getTypeArguments(target)[Math.min(i, targetArity - 1)];
17525
17539
const targetCheckType = sourceFlags & ElementFlags.Variadic && targetFlags & ElementFlags.Rest ? createArrayType(targetType) : targetType;
0 commit comments