@@ -18378,6 +18378,32 @@ namespace ts {
18378
18378
}
18379
18379
// Infer from the members of source and target only if the two types are possibly related
18380
18380
if (!typesDefinitelyUnrelated(source, target)) {
18381
+ if (isArrayType(source) || isTupleType(source)) {
18382
+ if (isTupleType(target)) {
18383
+ const sourceLength = isTupleType(source) ? getLengthOfTupleType(source) : 0;
18384
+ const targetLength = getLengthOfTupleType(target);
18385
+ const sourceRestType = isTupleType(source) ? getRestTypeOfTupleType(source) : getElementTypeOfArrayType(source);
18386
+ const targetRestType = getRestTypeOfTupleType(target);
18387
+ const fixedLength = targetLength < sourceLength || sourceRestType ? targetLength : sourceLength;
18388
+ for (let i = 0; i < fixedLength; i++) {
18389
+ inferFromTypes(i < sourceLength ? getTypeArguments(<TypeReference>source)[i] : sourceRestType!, getTypeArguments(target)[i]);
18390
+ }
18391
+ if (targetRestType) {
18392
+ const types = fixedLength < sourceLength ? getTypeArguments(<TypeReference>source).slice(fixedLength, sourceLength) : [];
18393
+ if (sourceRestType) {
18394
+ types.push(sourceRestType);
18395
+ }
18396
+ if (types.length) {
18397
+ inferFromTypes(getUnionType(types), targetRestType);
18398
+ }
18399
+ }
18400
+ return;
18401
+ }
18402
+ if (isArrayType(target)) {
18403
+ inferFromIndexTypes(source, target);
18404
+ return;
18405
+ }
18406
+ }
18381
18407
inferFromProperties(source, target);
18382
18408
inferFromSignatures(source, target, SignatureKind.Call);
18383
18409
inferFromSignatures(source, target, SignatureKind.Construct);
@@ -18386,32 +18412,6 @@ namespace ts {
18386
18412
}
18387
18413
18388
18414
function inferFromProperties(source: Type, target: Type) {
18389
- if (isArrayType(source) || isTupleType(source)) {
18390
- if (isTupleType(target)) {
18391
- const sourceLength = isTupleType(source) ? getLengthOfTupleType(source) : 0;
18392
- const targetLength = getLengthOfTupleType(target);
18393
- const sourceRestType = isTupleType(source) ? getRestTypeOfTupleType(source) : getElementTypeOfArrayType(source);
18394
- const targetRestType = getRestTypeOfTupleType(target);
18395
- const fixedLength = targetLength < sourceLength || sourceRestType ? targetLength : sourceLength;
18396
- for (let i = 0; i < fixedLength; i++) {
18397
- inferFromTypes(i < sourceLength ? getTypeArguments(<TypeReference>source)[i] : sourceRestType!, getTypeArguments(target)[i]);
18398
- }
18399
- if (targetRestType) {
18400
- const types = fixedLength < sourceLength ? getTypeArguments(<TypeReference>source).slice(fixedLength, sourceLength) : [];
18401
- if (sourceRestType) {
18402
- types.push(sourceRestType);
18403
- }
18404
- if (types.length) {
18405
- inferFromTypes(getUnionType(types), targetRestType);
18406
- }
18407
- }
18408
- return;
18409
- }
18410
- if (isArrayType(target)) {
18411
- inferFromIndexTypes(source, target);
18412
- return;
18413
- }
18414
- }
18415
18415
const properties = getPropertiesOfObjectType(target);
18416
18416
for (const targetProp of properties) {
18417
18417
const sourceProp = getPropertyOfType(source, targetProp.escapedName);
0 commit comments