@@ -17921,6 +17921,32 @@ namespace ts {
17921
17921
}
17922
17922
// Infer from the members of source and target only if the two types are possibly related
17923
17923
if (!typesDefinitelyUnrelated(source, target)) {
17924
+ if (isArrayType(source) || isTupleType(source)) {
17925
+ if (isTupleType(target)) {
17926
+ const sourceLength = isTupleType(source) ? getLengthOfTupleType(source) : 0;
17927
+ const targetLength = getLengthOfTupleType(target);
17928
+ const sourceRestType = isTupleType(source) ? getRestTypeOfTupleType(source) : getElementTypeOfArrayType(source);
17929
+ const targetRestType = getRestTypeOfTupleType(target);
17930
+ const fixedLength = targetLength < sourceLength || sourceRestType ? targetLength : sourceLength;
17931
+ for (let i = 0; i < fixedLength; i++) {
17932
+ inferFromTypes(i < sourceLength ? getTypeArguments(<TypeReference>source)[i] : sourceRestType!, getTypeArguments(target)[i]);
17933
+ }
17934
+ if (targetRestType) {
17935
+ const types = fixedLength < sourceLength ? getTypeArguments(<TypeReference>source).slice(fixedLength, sourceLength) : [];
17936
+ if (sourceRestType) {
17937
+ types.push(sourceRestType);
17938
+ }
17939
+ if (types.length) {
17940
+ inferFromTypes(getUnionType(types), targetRestType);
17941
+ }
17942
+ }
17943
+ return;
17944
+ }
17945
+ if (isArrayType(target)) {
17946
+ inferFromIndexTypes(source, target);
17947
+ return;
17948
+ }
17949
+ }
17924
17950
inferFromProperties(source, target);
17925
17951
inferFromSignatures(source, target, SignatureKind.Call);
17926
17952
inferFromSignatures(source, target, SignatureKind.Construct);
@@ -17929,32 +17955,6 @@ namespace ts {
17929
17955
}
17930
17956
17931
17957
function inferFromProperties(source: Type, target: Type) {
17932
- if (isArrayType(source) || isTupleType(source)) {
17933
- if (isTupleType(target)) {
17934
- const sourceLength = isTupleType(source) ? getLengthOfTupleType(source) : 0;
17935
- const targetLength = getLengthOfTupleType(target);
17936
- const sourceRestType = isTupleType(source) ? getRestTypeOfTupleType(source) : getElementTypeOfArrayType(source);
17937
- const targetRestType = getRestTypeOfTupleType(target);
17938
- const fixedLength = targetLength < sourceLength || sourceRestType ? targetLength : sourceLength;
17939
- for (let i = 0; i < fixedLength; i++) {
17940
- inferFromTypes(i < sourceLength ? getTypeArguments(<TypeReference>source)[i] : sourceRestType!, getTypeArguments(target)[i]);
17941
- }
17942
- if (targetRestType) {
17943
- const types = fixedLength < sourceLength ? getTypeArguments(<TypeReference>source).slice(fixedLength, sourceLength) : [];
17944
- if (sourceRestType) {
17945
- types.push(sourceRestType);
17946
- }
17947
- if (types.length) {
17948
- inferFromTypes(getUnionType(types), targetRestType);
17949
- }
17950
- }
17951
- return;
17952
- }
17953
- if (isArrayType(target)) {
17954
- inferFromIndexTypes(source, target);
17955
- return;
17956
- }
17957
- }
17958
17958
const properties = getPropertiesOfObjectType(target);
17959
17959
for (const targetProp of properties) {
17960
17960
const sourceProp = getPropertyOfType(source, targetProp.escapedName);
0 commit comments