@@ -17978,6 +17978,32 @@ namespace ts {
1797817978 }
1797917979 // Infer from the members of source and target only if the two types are possibly related
1798017980 if (!typesDefinitelyUnrelated(source, target)) {
17981+ if (isArrayType(source) || isTupleType(source)) {
17982+ if (isTupleType(target)) {
17983+ const sourceLength = isTupleType(source) ? getLengthOfTupleType(source) : 0;
17984+ const targetLength = getLengthOfTupleType(target);
17985+ const sourceRestType = isTupleType(source) ? getRestTypeOfTupleType(source) : getElementTypeOfArrayType(source);
17986+ const targetRestType = getRestTypeOfTupleType(target);
17987+ const fixedLength = targetLength < sourceLength || sourceRestType ? targetLength : sourceLength;
17988+ for (let i = 0; i < fixedLength; i++) {
17989+ inferFromTypes(i < sourceLength ? getTypeArguments(<TypeReference>source)[i] : sourceRestType!, getTypeArguments(target)[i]);
17990+ }
17991+ if (targetRestType) {
17992+ const types = fixedLength < sourceLength ? getTypeArguments(<TypeReference>source).slice(fixedLength, sourceLength) : [];
17993+ if (sourceRestType) {
17994+ types.push(sourceRestType);
17995+ }
17996+ if (types.length) {
17997+ inferFromTypes(getUnionType(types), targetRestType);
17998+ }
17999+ }
18000+ return;
18001+ }
18002+ if (isArrayType(target)) {
18003+ inferFromIndexTypes(source, target);
18004+ return;
18005+ }
18006+ }
1798118007 inferFromProperties(source, target);
1798218008 inferFromSignatures(source, target, SignatureKind.Call);
1798318009 inferFromSignatures(source, target, SignatureKind.Construct);
@@ -17986,32 +18012,6 @@ namespace ts {
1798618012 }
1798718013
1798818014 function inferFromProperties(source: Type, target: Type) {
17989- if (isArrayType(source) || isTupleType(source)) {
17990- if (isTupleType(target)) {
17991- const sourceLength = isTupleType(source) ? getLengthOfTupleType(source) : 0;
17992- const targetLength = getLengthOfTupleType(target);
17993- const sourceRestType = isTupleType(source) ? getRestTypeOfTupleType(source) : getElementTypeOfArrayType(source);
17994- const targetRestType = getRestTypeOfTupleType(target);
17995- const fixedLength = targetLength < sourceLength || sourceRestType ? targetLength : sourceLength;
17996- for (let i = 0; i < fixedLength; i++) {
17997- inferFromTypes(i < sourceLength ? getTypeArguments(<TypeReference>source)[i] : sourceRestType!, getTypeArguments(target)[i]);
17998- }
17999- if (targetRestType) {
18000- const types = fixedLength < sourceLength ? getTypeArguments(<TypeReference>source).slice(fixedLength, sourceLength) : [];
18001- if (sourceRestType) {
18002- types.push(sourceRestType);
18003- }
18004- if (types.length) {
18005- inferFromTypes(getUnionType(types), targetRestType);
18006- }
18007- }
18008- return;
18009- }
18010- if (isArrayType(target)) {
18011- inferFromIndexTypes(source, target);
18012- return;
18013- }
18014- }
1801518015 const properties = getPropertiesOfObjectType(target);
1801618016 for (const targetProp of properties) {
1801718017 const sourceProp = getPropertyOfType(source, targetProp.escapedName);
0 commit comments