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