@@ -18112,6 +18112,32 @@ namespace ts {
1811218112 }
1811318113 // Infer from the members of source and target only if the two types are possibly related
1811418114 if (!typesDefinitelyUnrelated(source, target)) {
18115+ if (isArrayType(source) || isTupleType(source)) {
18116+ if (isTupleType(target)) {
18117+ const sourceLength = isTupleType(source) ? getLengthOfTupleType(source) : 0;
18118+ const targetLength = getLengthOfTupleType(target);
18119+ const sourceRestType = isTupleType(source) ? getRestTypeOfTupleType(source) : getElementTypeOfArrayType(source);
18120+ const targetRestType = getRestTypeOfTupleType(target);
18121+ const fixedLength = targetLength < sourceLength || sourceRestType ? targetLength : sourceLength;
18122+ for (let i = 0; i < fixedLength; i++) {
18123+ inferFromTypes(i < sourceLength ? getTypeArguments(<TypeReference>source)[i] : sourceRestType!, getTypeArguments(target)[i]);
18124+ }
18125+ if (targetRestType) {
18126+ const types = fixedLength < sourceLength ? getTypeArguments(<TypeReference>source).slice(fixedLength, sourceLength) : [];
18127+ if (sourceRestType) {
18128+ types.push(sourceRestType);
18129+ }
18130+ if (types.length) {
18131+ inferFromTypes(getUnionType(types), targetRestType);
18132+ }
18133+ }
18134+ return;
18135+ }
18136+ if (isArrayType(target)) {
18137+ inferFromIndexTypes(source, target);
18138+ return;
18139+ }
18140+ }
1811518141 inferFromProperties(source, target);
1811618142 inferFromSignatures(source, target, SignatureKind.Call);
1811718143 inferFromSignatures(source, target, SignatureKind.Construct);
@@ -18120,32 +18146,6 @@ namespace ts {
1812018146 }
1812118147
1812218148 function inferFromProperties(source: Type, target: Type) {
18123- if (isArrayType(source) || isTupleType(source)) {
18124- if (isTupleType(target)) {
18125- const sourceLength = isTupleType(source) ? getLengthOfTupleType(source) : 0;
18126- const targetLength = getLengthOfTupleType(target);
18127- const sourceRestType = isTupleType(source) ? getRestTypeOfTupleType(source) : getElementTypeOfArrayType(source);
18128- const targetRestType = getRestTypeOfTupleType(target);
18129- const fixedLength = targetLength < sourceLength || sourceRestType ? targetLength : sourceLength;
18130- for (let i = 0; i < fixedLength; i++) {
18131- inferFromTypes(i < sourceLength ? getTypeArguments(<TypeReference>source)[i] : sourceRestType!, getTypeArguments(target)[i]);
18132- }
18133- if (targetRestType) {
18134- const types = fixedLength < sourceLength ? getTypeArguments(<TypeReference>source).slice(fixedLength, sourceLength) : [];
18135- if (sourceRestType) {
18136- types.push(sourceRestType);
18137- }
18138- if (types.length) {
18139- inferFromTypes(getUnionType(types), targetRestType);
18140- }
18141- }
18142- return;
18143- }
18144- if (isArrayType(target)) {
18145- inferFromIndexTypes(source, target);
18146- return;
18147- }
18148- }
1814918149 const properties = getPropertiesOfObjectType(target);
1815018150 for (const targetProp of properties) {
1815118151 const sourceProp = getPropertyOfType(source, targetProp.escapedName);
0 commit comments