@@ -5058,9 +5058,10 @@ namespace ts {
5058
5058
if (!links.resolvedSignature) {
5059
5059
const parameters: Symbol[] = [];
5060
5060
let hasLiteralTypes = false;
5061
- let minArgumentCount = -1 ;
5061
+ let minArgumentCount = 0 ;
5062
5062
let thisParameter: Symbol = undefined;
5063
5063
let hasThisParameter: boolean;
5064
+ const iife = getImmediatelyInvokedFunctionExpression(declaration);
5064
5065
const isJSConstructSignature = isJSDocConstructSignature(declaration);
5065
5066
5066
5067
// If this is a JSDoc construct signature, then skip the first parameter in the
@@ -5087,14 +5088,12 @@ namespace ts {
5087
5088
hasLiteralTypes = true;
5088
5089
}
5089
5090
5090
- if (param.initializer || param.questionToken || param.dotDotDotToken || isJSDocOptionalParameter(param)) {
5091
- if (minArgumentCount < 0) {
5092
- minArgumentCount = i - (hasThisParameter ? 1 : 0);
5093
- }
5094
- }
5095
- else {
5096
- // If we see any required parameters, it means the prior ones were not in fact optional.
5097
- minArgumentCount = -1;
5091
+ // Record a new minimum argument count if this is not an optional parameter
5092
+ const isOptionalParameter = param.initializer || param.questionToken || param.dotDotDotToken ||
5093
+ iife && parameters.length > iife.arguments.length && !param.type ||
5094
+ isJSDocOptionalParameter(param);
5095
+ if (!isOptionalParameter) {
5096
+ minArgumentCount = parameters.length;
5098
5097
}
5099
5098
}
5100
5099
@@ -5109,13 +5108,6 @@ namespace ts {
5109
5108
}
5110
5109
}
5111
5110
5112
- if (minArgumentCount < 0) {
5113
- minArgumentCount = declaration.parameters.length - (hasThisParameter ? 1 : 0);
5114
- }
5115
- if (isJSConstructSignature) {
5116
- minArgumentCount--;
5117
- }
5118
-
5119
5111
const classType = declaration.kind === SyntaxKind.Constructor ?
5120
5112
getDeclaredTypeOfClassOrInterface(getMergedSymbol((<ClassDeclaration>declaration.parent).symbol))
5121
5113
: undefined;
@@ -10933,23 +10925,23 @@ namespace ts {
10933
10925
const func = parameter.parent;
10934
10926
if (isContextSensitiveFunctionOrObjectLiteralMethod(func)) {
10935
10927
const iife = getImmediatelyInvokedFunctionExpression(func);
10936
- if (iife) {
10928
+ if (iife && iife.arguments ) {
10937
10929
const indexOfParameter = indexOf(func.parameters, parameter);
10938
- if (iife.arguments && indexOfParameter < iife.arguments.length ) {
10939
- if (parameter.dotDotDotToken) {
10940
- const restTypes: Type[] = [];
10941
- for (let i = indexOfParameter; i < iife.arguments.length; i++) {
10942
- restTypes.push(getWidenedLiteralType(checkExpression(iife.arguments[i])));
10943
- }
10944
- return createArrayType(getUnionType(restTypes));
10945
- }
10946
- const links = getNodeLinks(iife) ;
10947
- const cached = links.resolvedSignature;
10948
- links.resolvedSignature = anySignature;
10949
- const type = getWidenedLiteralType(checkExpression(iife.arguments[indexOfParameter]));
10950
- links.resolvedSignature = cached ;
10951
- return type ;
10952
- }
10930
+ if (parameter.dotDotDotToken ) {
10931
+ const restTypes: Type[] = [];
10932
+ for (let i = indexOfParameter; i < iife.arguments.length; i++) {
10933
+ restTypes.push(getWidenedLiteralType(checkExpression( iife.arguments[i])));
10934
+ }
10935
+ return restTypes.length ? createArrayType(getUnionType(restTypes)) : undefined;
10936
+ }
10937
+ const links = getNodeLinks(iife);
10938
+ const cached = links.resolvedSignature ;
10939
+ links.resolvedSignature = anySignature ;
10940
+ const type = indexOfParameter < iife.arguments.length ?
10941
+ getWidenedLiteralType(checkExpression(iife.arguments[indexOfParameter])) :
10942
+ parameter.initializer ? undefined : undefinedWideningType ;
10943
+ links.resolvedSignature = cached ;
10944
+ return type;
10953
10945
}
10954
10946
const contextualSignature = getContextualSignature(func);
10955
10947
if (contextualSignature) {
0 commit comments