@@ -18112,6 +18112,32 @@ namespace ts {
18112
18112
}
18113
18113
// Infer from the members of source and target only if the two types are possibly related
18114
18114
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
+ }
18115
18141
inferFromProperties(source, target);
18116
18142
inferFromSignatures(source, target, SignatureKind.Call);
18117
18143
inferFromSignatures(source, target, SignatureKind.Construct);
@@ -18120,32 +18146,6 @@ namespace ts {
18120
18146
}
18121
18147
18122
18148
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
- }
18149
18149
const properties = getPropertiesOfObjectType(target);
18150
18150
for (const targetProp of properties) {
18151
18151
const sourceProp = getPropertyOfType(source, targetProp.escapedName);
0 commit comments