@@ -10322,8 +10322,8 @@ namespace ts {
10322
10322
return -1;
10323
10323
}
10324
10324
10325
- function hasCorrectArity(node: CallLikeExpression, args: Expression[], signature: Signature) {
10326
- let adjustedArgCount : number; // Apparent number of arguments we will have in this call
10325
+ function hasCorrectArity(node: CallLikeExpression, args: Expression[], signature: Signature, signatureHelpTrailingComma = false ) {
10326
+ let argCount : number; // Apparent number of arguments we will have in this call
10327
10327
let typeArguments: NodeArray<TypeNode>; // Type arguments (undefined if none)
10328
10328
let callIsIncomplete: boolean; // In incomplete call we want to be lenient when we have too few arguments
10329
10329
let isDecorator: boolean;
@@ -10334,7 +10334,7 @@ namespace ts {
10334
10334
10335
10335
// Even if the call is incomplete, we'll have a missing expression as our last argument,
10336
10336
// so we can say the count is just the arg list length
10337
- adjustedArgCount = args.length;
10337
+ argCount = args.length;
10338
10338
typeArguments = undefined;
10339
10339
10340
10340
if (tagExpression.template.kind === SyntaxKind.TemplateExpression) {
@@ -10357,7 +10357,7 @@ namespace ts {
10357
10357
else if (node.kind === SyntaxKind.Decorator) {
10358
10358
isDecorator = true;
10359
10359
typeArguments = undefined;
10360
- adjustedArgCount = getEffectiveArgumentCount(node, /*args*/ undefined, signature);
10360
+ argCount = getEffectiveArgumentCount(node, /*args*/ undefined, signature);
10361
10361
}
10362
10362
else {
10363
10363
const callExpression = <CallExpression>node;
@@ -10368,8 +10368,7 @@ namespace ts {
10368
10368
return signature.minArgumentCount === 0;
10369
10369
}
10370
10370
10371
- // For IDE scenarios we may have an incomplete call, so a trailing comma is tantamount to adding another argument.
10372
- adjustedArgCount = callExpression.arguments.hasTrailingComma ? args.length + 1 : args.length;
10371
+ argCount = signatureHelpTrailingComma ? args.length + 1 : args.length;
10373
10372
10374
10373
// If we are missing the close paren, the call is incomplete.
10375
10374
callIsIncomplete = (<CallExpression>callExpression).arguments.end === callExpression.end;
@@ -10393,12 +10392,12 @@ namespace ts {
10393
10392
}
10394
10393
10395
10394
// Too many arguments implies incorrect arity.
10396
- if (!signature.hasRestParameter && adjustedArgCount > signature.parameters.length) {
10395
+ if (!signature.hasRestParameter && argCount > signature.parameters.length) {
10397
10396
return false;
10398
10397
}
10399
10398
10400
10399
// If the call is incomplete, we should skip the lower bound check.
10401
- const hasEnoughArguments = adjustedArgCount >= signature.minArgumentCount;
10400
+ const hasEnoughArguments = argCount >= signature.minArgumentCount;
10402
10401
return callIsIncomplete || hasEnoughArguments;
10403
10402
}
10404
10403
@@ -10970,6 +10969,11 @@ namespace ts {
10970
10969
let resultOfFailedInference: InferenceContext;
10971
10970
let result: Signature;
10972
10971
10972
+ // If we are in signature help, a trailing comma indicates that we intend to provide another argument,
10973
+ // so we will only accept overloads with arity at least 1 higher than the current number of provided arguments.
10974
+ const signatureHelpTrailingComma =
10975
+ candidatesOutArray && node.kind === SyntaxKind.CallExpression && (<CallExpression>node).arguments.hasTrailingComma;
10976
+
10973
10977
// Section 4.12.1:
10974
10978
// if the candidate list contains one or more signatures for which the type of each argument
10975
10979
// expression is a subtype of each corresponding parameter type, the return type of the first
@@ -10981,14 +10985,14 @@ namespace ts {
10981
10985
// is just important for choosing the best signature. So in the case where there is only one
10982
10986
// signature, the subtype pass is useless. So skipping it is an optimization.
10983
10987
if (candidates.length > 1) {
10984
- result = chooseOverload(candidates, subtypeRelation);
10988
+ result = chooseOverload(candidates, subtypeRelation, signatureHelpTrailingComma );
10985
10989
}
10986
10990
if (!result) {
10987
10991
// Reinitialize these pointers for round two
10988
10992
candidateForArgumentError = undefined;
10989
10993
candidateForTypeArgumentError = undefined;
10990
10994
resultOfFailedInference = undefined;
10991
- result = chooseOverload(candidates, assignableRelation);
10995
+ result = chooseOverload(candidates, assignableRelation, signatureHelpTrailingComma );
10992
10996
}
10993
10997
if (result) {
10994
10998
return result;
@@ -11059,9 +11063,9 @@ namespace ts {
11059
11063
diagnostics.add(createDiagnosticForNodeFromMessageChain(node, errorInfo));
11060
11064
}
11061
11065
11062
- function chooseOverload(candidates: Signature[], relation: Map<RelationComparisonResult>) {
11066
+ function chooseOverload(candidates: Signature[], relation: Map<RelationComparisonResult>, signatureHelpTrailingComma = false ) {
11063
11067
for (const originalCandidate of candidates) {
11064
- if (!hasCorrectArity(node, args, originalCandidate)) {
11068
+ if (!hasCorrectArity(node, args, originalCandidate, signatureHelpTrailingComma )) {
11065
11069
continue;
11066
11070
}
11067
11071
@@ -18028,10 +18032,6 @@ namespace ts {
18028
18032
}
18029
18033
18030
18034
function checkGrammarParameterList(parameters: NodeArray<ParameterDeclaration>) {
18031
- if (checkGrammarForDisallowedTrailingComma(parameters)) {
18032
- return true;
18033
- }
18034
-
18035
18035
let seenOptionalParameter = false;
18036
18036
const parameterCount = parameters.length;
18037
18037
@@ -18150,8 +18150,7 @@ namespace ts {
18150
18150
}
18151
18151
18152
18152
function checkGrammarArguments(node: CallExpression, args: NodeArray<Expression>): boolean {
18153
- return checkGrammarForDisallowedTrailingComma(args) ||
18154
- checkGrammarForOmittedArgument(node, args);
18153
+ return checkGrammarForOmittedArgument(node, args);
18155
18154
}
18156
18155
18157
18156
function checkGrammarHeritageClause(node: HeritageClause): boolean {
0 commit comments