@@ -17273,7 +17273,11 @@ namespace ts {
1727317273 result &= signaturesRelatedTo(source, type, SignatureKind.Construct, /*reportStructuralErrors*/ false);
1727417274 if (result) {
1727517275 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))) {
1727717281 result &= indexTypesRelatedTo(source, type, IndexKind.Number, /*sourceIsPrimitive*/ false, /*reportStructuralErrors*/ false, IntersectionState.None);
1727817282 }
1727917283 }
@@ -17498,6 +17502,7 @@ namespace ts {
1749817502 for (let i = 0; i < maxArity; i++) {
1749917503 const targetFlags = i < targetArity ? target.target.elementFlags[i] : targetRestFlag;
1750017504 const sourceFlags = isTupleType(source) && i < sourceArity ? source.target.elementFlags[i] : sourceRestFlag;
17505+ let canExcludeDiscriminants = !!excludedProperties;
1750117506 if (sourceFlags && targetFlags) {
1750217507 if (targetFlags & ElementFlags.Variadic && !(sourceFlags & ElementFlags.Variadic) ||
1750317508 (sourceFlags & ElementFlags.Variadic && !(targetFlags & ElementFlags.Variable))) {
@@ -17514,6 +17519,15 @@ namespace ts {
1751417519 return Ternary.False;
1751517520 }
1751617521 }
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+ }
1751717531 const sourceType = getTypeArguments(source)[Math.min(i, sourceArity - 1)];
1751817532 const targetType = getTypeArguments(target)[Math.min(i, targetArity - 1)];
1751917533 const targetCheckType = sourceFlags & ElementFlags.Variadic && targetFlags & ElementFlags.Rest ? createArrayType(targetType) : targetType;
0 commit comments