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