@@ -17279,7 +17279,11 @@ namespace ts {
1727917279 result &= signaturesRelatedTo(source, type, SignatureKind.Construct, /*reportStructuralErrors*/ false);
1728017280 if (result) {
1728117281 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))) {
1728317287 result &= indexTypesRelatedTo(source, type, IndexKind.Number, /*sourceIsPrimitive*/ false, /*reportStructuralErrors*/ false, IntersectionState.None);
1728417288 }
1728517289 }
@@ -17504,6 +17508,7 @@ namespace ts {
1750417508 for (let i = 0; i < maxArity; i++) {
1750517509 const targetFlags = i < targetArity ? target.target.elementFlags[i] : targetRestFlag;
1750617510 const sourceFlags = isTupleType(source) && i < sourceArity ? source.target.elementFlags[i] : sourceRestFlag;
17511+ let canExcludeDiscriminants = !!excludedProperties;
1750717512 if (sourceFlags && targetFlags) {
1750817513 if (targetFlags & ElementFlags.Variadic && !(sourceFlags & ElementFlags.Variadic) ||
1750917514 (sourceFlags & ElementFlags.Variadic && !(targetFlags & ElementFlags.Variable))) {
@@ -17520,6 +17525,15 @@ namespace ts {
1752017525 return Ternary.False;
1752117526 }
1752217527 }
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+ }
1752317537 const sourceType = getTypeArguments(source)[Math.min(i, sourceArity - 1)];
1752417538 const targetType = getTypeArguments(target)[Math.min(i, targetArity - 1)];
1752517539 const targetCheckType = sourceFlags & ElementFlags.Variadic && targetFlags & ElementFlags.Rest ? createArrayType(targetType) : targetType;
0 commit comments