@@ -17978,6 +17978,32 @@ namespace ts {
17978
17978
}
17979
17979
// Infer from the members of source and target only if the two types are possibly related
17980
17980
if (!typesDefinitelyUnrelated(source, target)) {
17981
+ if (isArrayType(source) || isTupleType(source)) {
17982
+ if (isTupleType(target)) {
17983
+ const sourceLength = isTupleType(source) ? getLengthOfTupleType(source) : 0;
17984
+ const targetLength = getLengthOfTupleType(target);
17985
+ const sourceRestType = isTupleType(source) ? getRestTypeOfTupleType(source) : getElementTypeOfArrayType(source);
17986
+ const targetRestType = getRestTypeOfTupleType(target);
17987
+ const fixedLength = targetLength < sourceLength || sourceRestType ? targetLength : sourceLength;
17988
+ for (let i = 0; i < fixedLength; i++) {
17989
+ inferFromTypes(i < sourceLength ? getTypeArguments(<TypeReference>source)[i] : sourceRestType!, getTypeArguments(target)[i]);
17990
+ }
17991
+ if (targetRestType) {
17992
+ const types = fixedLength < sourceLength ? getTypeArguments(<TypeReference>source).slice(fixedLength, sourceLength) : [];
17993
+ if (sourceRestType) {
17994
+ types.push(sourceRestType);
17995
+ }
17996
+ if (types.length) {
17997
+ inferFromTypes(getUnionType(types), targetRestType);
17998
+ }
17999
+ }
18000
+ return;
18001
+ }
18002
+ if (isArrayType(target)) {
18003
+ inferFromIndexTypes(source, target);
18004
+ return;
18005
+ }
18006
+ }
17981
18007
inferFromProperties(source, target);
17982
18008
inferFromSignatures(source, target, SignatureKind.Call);
17983
18009
inferFromSignatures(source, target, SignatureKind.Construct);
@@ -17986,32 +18012,6 @@ namespace ts {
17986
18012
}
17987
18013
17988
18014
function inferFromProperties(source: Type, target: Type) {
17989
- if (isArrayType(source) || isTupleType(source)) {
17990
- if (isTupleType(target)) {
17991
- const sourceLength = isTupleType(source) ? getLengthOfTupleType(source) : 0;
17992
- const targetLength = getLengthOfTupleType(target);
17993
- const sourceRestType = isTupleType(source) ? getRestTypeOfTupleType(source) : getElementTypeOfArrayType(source);
17994
- const targetRestType = getRestTypeOfTupleType(target);
17995
- const fixedLength = targetLength < sourceLength || sourceRestType ? targetLength : sourceLength;
17996
- for (let i = 0; i < fixedLength; i++) {
17997
- inferFromTypes(i < sourceLength ? getTypeArguments(<TypeReference>source)[i] : sourceRestType!, getTypeArguments(target)[i]);
17998
- }
17999
- if (targetRestType) {
18000
- const types = fixedLength < sourceLength ? getTypeArguments(<TypeReference>source).slice(fixedLength, sourceLength) : [];
18001
- if (sourceRestType) {
18002
- types.push(sourceRestType);
18003
- }
18004
- if (types.length) {
18005
- inferFromTypes(getUnionType(types), targetRestType);
18006
- }
18007
- }
18008
- return;
18009
- }
18010
- if (isArrayType(target)) {
18011
- inferFromIndexTypes(source, target);
18012
- return;
18013
- }
18014
- }
18015
18015
const properties = getPropertiesOfObjectType(target);
18016
18016
for (const targetProp of properties) {
18017
18017
const sourceProp = getPropertyOfType(source, targetProp.escapedName);
0 commit comments