Skip to content

Commit 9d92a43

Browse files
committed
Don't inferFromIndexTypes() twice
1 parent 0f5ddd2 commit 9d92a43

File tree

2 files changed

+27
-27
lines changed

2 files changed

+27
-27
lines changed

src/compiler/checker.ts

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -17978,6 +17978,32 @@ namespace ts {
1797817978
}
1797917979
// Infer from the members of source and target only if the two types are possibly related
1798017980
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+
}
1798118007
inferFromProperties(source, target);
1798218008
inferFromSignatures(source, target, SignatureKind.Call);
1798318009
inferFromSignatures(source, target, SignatureKind.Construct);
@@ -17986,32 +18012,6 @@ namespace ts {
1798618012
}
1798718013

1798818014
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-
}
1801518015
const properties = getPropertiesOfObjectType(target);
1801618016
for (const targetProp of properties) {
1801718017
const sourceProp = getPropertyOfType(source, targetProp.escapedName);

tests/baselines/reference/restTupleElements1.types

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ f0([]); // Error
173173
>[] : never[]
174174

175175
f0([1]);
176-
>f0([1]) : [number, number]
176+
>f0([1]) : [number, unknown]
177177
>f0 : <T, U>(x: [T, ...U[]]) => [T, U]
178178
>[1] : [number]
179179
>1 : 1

0 commit comments

Comments
 (0)