@@ -18301,6 +18301,32 @@ namespace ts {
18301
18301
}
18302
18302
// Infer from the members of source and target only if the two types are possibly related
18303
18303
if (!typesDefinitelyUnrelated(source, target)) {
18304
+ if (isArrayType(source) || isTupleType(source)) {
18305
+ if (isTupleType(target)) {
18306
+ const sourceLength = isTupleType(source) ? getLengthOfTupleType(source) : 0;
18307
+ const targetLength = getLengthOfTupleType(target);
18308
+ const sourceRestType = isTupleType(source) ? getRestTypeOfTupleType(source) : getElementTypeOfArrayType(source);
18309
+ const targetRestType = getRestTypeOfTupleType(target);
18310
+ const fixedLength = targetLength < sourceLength || sourceRestType ? targetLength : sourceLength;
18311
+ for (let i = 0; i < fixedLength; i++) {
18312
+ inferFromTypes(i < sourceLength ? getTypeArguments(<TypeReference>source)[i] : sourceRestType!, getTypeArguments(target)[i]);
18313
+ }
18314
+ if (targetRestType) {
18315
+ const types = fixedLength < sourceLength ? getTypeArguments(<TypeReference>source).slice(fixedLength, sourceLength) : [];
18316
+ if (sourceRestType) {
18317
+ types.push(sourceRestType);
18318
+ }
18319
+ if (types.length) {
18320
+ inferFromTypes(getUnionType(types), targetRestType);
18321
+ }
18322
+ }
18323
+ return;
18324
+ }
18325
+ if (isArrayType(target)) {
18326
+ inferFromIndexTypes(source, target);
18327
+ return;
18328
+ }
18329
+ }
18304
18330
inferFromProperties(source, target);
18305
18331
inferFromSignatures(source, target, SignatureKind.Call);
18306
18332
inferFromSignatures(source, target, SignatureKind.Construct);
@@ -18309,32 +18335,6 @@ namespace ts {
18309
18335
}
18310
18336
18311
18337
function inferFromProperties(source: Type, target: Type) {
18312
- if (isArrayType(source) || isTupleType(source)) {
18313
- if (isTupleType(target)) {
18314
- const sourceLength = isTupleType(source) ? getLengthOfTupleType(source) : 0;
18315
- const targetLength = getLengthOfTupleType(target);
18316
- const sourceRestType = isTupleType(source) ? getRestTypeOfTupleType(source) : getElementTypeOfArrayType(source);
18317
- const targetRestType = getRestTypeOfTupleType(target);
18318
- const fixedLength = targetLength < sourceLength || sourceRestType ? targetLength : sourceLength;
18319
- for (let i = 0; i < fixedLength; i++) {
18320
- inferFromTypes(i < sourceLength ? getTypeArguments(<TypeReference>source)[i] : sourceRestType!, getTypeArguments(target)[i]);
18321
- }
18322
- if (targetRestType) {
18323
- const types = fixedLength < sourceLength ? getTypeArguments(<TypeReference>source).slice(fixedLength, sourceLength) : [];
18324
- if (sourceRestType) {
18325
- types.push(sourceRestType);
18326
- }
18327
- if (types.length) {
18328
- inferFromTypes(getUnionType(types), targetRestType);
18329
- }
18330
- }
18331
- return;
18332
- }
18333
- if (isArrayType(target)) {
18334
- inferFromIndexTypes(source, target);
18335
- return;
18336
- }
18337
- }
18338
18338
const properties = getPropertiesOfObjectType(target);
18339
18339
for (const targetProp of properties) {
18340
18340
const sourceProp = getPropertyOfType(source, targetProp.escapedName);
0 commit comments