Skip to content

Commit e72af80

Browse files
committed
Improve inference between types with multiple signatures
1 parent fb7efcf commit e72af80

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

src/compiler/checker.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25056,12 +25056,16 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
2505625056

2505725057
function inferFromSignatures(source: Type, target: Type, kind: SignatureKind) {
2505825058
const sourceSignatures = getSignaturesOfType(source, kind);
25059-
const targetSignatures = getSignaturesOfType(target, kind);
2506025059
const sourceLen = sourceSignatures.length;
25061-
const targetLen = targetSignatures.length;
25062-
const len = sourceLen < targetLen ? sourceLen : targetLen;
25063-
for (let i = 0; i < len; i++) {
25064-
inferFromSignature(getBaseSignature(sourceSignatures[sourceLen - len + i]), getErasedSignature(targetSignatures[targetLen - len + i]));
25060+
if (sourceLen > 0) {
25061+
// We match source and target signatures from the bottom up, and if the source has fewer signatures
25062+
// than the target, we infer from the first source signature to the excess target signatures.
25063+
const targetSignatures = getSignaturesOfType(target, kind);
25064+
const targetLen = targetSignatures.length;
25065+
for (let i = 0; i < targetLen; i++) {
25066+
const sourceIndex = Math.max(sourceLen - targetLen + i, 0);
25067+
inferFromSignature(getBaseSignature(sourceSignatures[sourceIndex]), getErasedSignature(targetSignatures[i]));
25068+
}
2506525069
}
2506625070
}
2506725071

0 commit comments

Comments
 (0)