Skip to content

Commit 3e71d50

Browse files
committed
Ignore optionality when skipping overloads
1 parent 5a336fe commit 3e71d50

File tree

2 files changed

+3
-10
lines changed

2 files changed

+3
-10
lines changed

src/compiler/checker.ts

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11912,16 +11912,9 @@ namespace ts {
1191211912

1191311913
function isAritySmaller(sourceType: Type, target: Expression) {
1191411914
if (isFunctionExpressionOrArrowFunction(target) && isFunctionType(sourceType)) {
11915-
let targetParameterCount = 0;
11916-
for (; targetParameterCount < target.parameters.length; targetParameterCount++) {
11917-
const param = target.parameters[targetParameterCount];
11918-
if (param.initializer || param.questionToken || param.dotDotDotToken || isJSDocOptionalParameter(param)) {
11919-
break;
11920-
}
11921-
}
1192211915
const sourceSignatures = getSignaturesOfType(sourceType, SignatureKind.Call);
1192311916
const sourceLengths = sourceSignatures.map(sig => !sig.hasRestParameter ? sig.parameters.length : Number.MAX_VALUE);
11924-
return forEach(sourceLengths, len => len < targetParameterCount);
11917+
return forEach(sourceLengths, len => len < target.parameters.length);
1192511918
}
1192611919

1192711920
return false;

tests/baselines/reference/genericCallWithOverloadedFunctionTypedArguments.types

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,8 @@ module GenericParameter {
122122
>'' : ""
123123

124124
var r11 = foo6(<T>(x: T, y?: T) => ''); // any => string (+1 overload)
125-
>r11 : { (x: any): string; (x: any, y?: any): string; }
126-
>foo6(<T>(x: T, y?: T) => '') : { (x: any): string; (x: any, y?: any): string; }
125+
>r11 : any
126+
>foo6(<T>(x: T, y?: T) => '') : any
127127
>foo6 : <T>(cb: { (x: T): string; (x: T, y?: T): string; }) => { (x: T): string; (x: T, y?: T): string; }
128128
><T>(x: T, y?: T) => '' : <T>(x: T, y?: T) => string
129129
>T : T

0 commit comments

Comments
 (0)