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