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