@@ -18108,6 +18108,32 @@ namespace ts {
18108
18108
}
18109
18109
// Infer from the members of source and target only if the two types are possibly related
18110
18110
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
+ }
18111
18137
inferFromProperties(source, target);
18112
18138
inferFromSignatures(source, target, SignatureKind.Call);
18113
18139
inferFromSignatures(source, target, SignatureKind.Construct);
@@ -18116,32 +18142,6 @@ namespace ts {
18116
18142
}
18117
18143
18118
18144
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
- }
18145
18145
const properties = getPropertiesOfObjectType(target);
18146
18146
for (const targetProp of properties) {
18147
18147
const sourceProp = getPropertyOfType(source, targetProp.escapedName);
0 commit comments