@@ -18638,7 +18638,7 @@ namespace ts {
18638
18638
return getInferredTypes(context);
18639
18639
}
18640
18640
18641
- function inferTypeArguments(node: CallLikeExpression, signature: Signature, args: ReadonlyArray<Expression>, excludeArgument: boolean[] | undefined, context: InferenceContext): Type[] {
18641
+ function inferTypeArguments(node: CallLikeExpression, signature: Signature, args: ReadonlyArray<Expression>, excludeArgument: ReadonlyArray< boolean> | undefined, context: InferenceContext): Type[] {
18642
18642
// Clear out all the inference results from the last time inferTypeArguments was called on this context
18643
18643
for (const inference of context.inferences) {
18644
18644
// As an optimization, we don't have to clear (and later recompute) inferred types
@@ -19052,19 +19052,7 @@ namespace ts {
19052
19052
// For a decorator, no arguments are susceptible to contextual typing due to the fact
19053
19053
// decorators are applied to a declaration by the emitter, and not to an expression.
19054
19054
const isSingleNonGenericCandidate = candidates.length === 1 && !candidates[0].typeParameters;
19055
- let excludeArgument: boolean[] | undefined;
19056
- if (!isDecorator && !isSingleNonGenericCandidate) {
19057
- // We do not need to call `getEffectiveArgumentCount` here as it only
19058
- // applies when calculating the number of arguments for a decorator.
19059
- for (let i = 0; i < args.length; i++) {
19060
- if (isContextSensitive(args[i])) {
19061
- if (!excludeArgument) {
19062
- excludeArgument = new Array(args.length);
19063
- }
19064
- excludeArgument[i] = true;
19065
- }
19066
- }
19067
- }
19055
+ let excludeArgument = !isDecorator && !isSingleNonGenericCandidate ? getExcludeArgument(args) : undefined;
19068
19056
19069
19057
// The following variables are captured and modified by calls to chooseOverload.
19070
19058
// If overload resolution or type argument inference fails, we want to report the
@@ -19227,6 +19215,21 @@ namespace ts {
19227
19215
}
19228
19216
}
19229
19217
19218
+ function getExcludeArgument(args: ReadonlyArray<Expression>): boolean[] | undefined {
19219
+ let excludeArgument: boolean[] | undefined;
19220
+ // We do not need to call `getEffectiveArgumentCount` here as it only
19221
+ // applies when calculating the number of arguments for a decorator.
19222
+ for (let i = 0; i < args.length; i++) {
19223
+ if (isContextSensitive(args[i])) {
19224
+ if (!excludeArgument) {
19225
+ excludeArgument = new Array(args.length);
19226
+ }
19227
+ excludeArgument[i] = true;
19228
+ }
19229
+ }
19230
+ return excludeArgument;
19231
+ }
19232
+
19230
19233
// No signature was applicable. We have already reported the errors for the invalid signature.
19231
19234
// If this is a type resolution session, e.g. Language Service, try to get better information than anySignature.
19232
19235
function getCandidateForOverloadFailure(
@@ -19305,17 +19308,29 @@ namespace ts {
19305
19308
return candidate;
19306
19309
}
19307
19310
19308
- const typeArgumentNodes: ReadonlyArray<TypeNode> = callLikeExpressionMayHaveTypeArguments(node) ? node.typeArguments || emptyArray : emptyArray;
19311
+ const typeArgumentNodes: ReadonlyArray<TypeNode> | undefined = callLikeExpressionMayHaveTypeArguments(node) ? node.typeArguments : undefined;
19312
+ const instantiated = typeArgumentNodes
19313
+ ? createSignatureInstantiation(candidate, getTypeArgumentsFromNodes(typeArgumentNodes, typeParameters, isInJavaScriptFile(node)))
19314
+ : inferSignatureInstantiationForOverloadFailure(node, typeParameters, candidate, args);
19315
+ candidates[bestIndex] = instantiated;
19316
+ return instantiated;
19317
+ }
19318
+
19319
+ function getTypeArgumentsFromNodes(typeArgumentNodes: ReadonlyArray<TypeNode>, typeParameters: ReadonlyArray<TypeParameter>, isJs: boolean): ReadonlyArray<Type> {
19309
19320
const typeArguments = typeArgumentNodes.map(getTypeOfNode);
19310
19321
while (typeArguments.length > typeParameters.length) {
19311
19322
typeArguments.pop();
19312
19323
}
19313
19324
while (typeArguments.length < typeParameters.length) {
19314
- typeArguments.push(getConstraintOfTypeParameter(typeParameters[typeArguments.length]) || getDefaultTypeArgumentType(isInJavaScriptFile(node) ));
19325
+ typeArguments.push(getConstraintOfTypeParameter(typeParameters[typeArguments.length]) || getDefaultTypeArgumentType(isJs ));
19315
19326
}
19316
- const instantiated = createSignatureInstantiation(candidate, typeArguments);
19317
- candidates[bestIndex] = instantiated;
19318
- return instantiated;
19327
+ return typeArguments;
19328
+ }
19329
+
19330
+ function inferSignatureInstantiationForOverloadFailure(node: CallLikeExpression, typeParameters: ReadonlyArray<TypeParameter>, candidate: Signature, args: ReadonlyArray<Expression>): Signature {
19331
+ const inferenceContext = createInferenceContext(typeParameters, candidate, /*flags*/ isInJavaScriptFile(node) ? InferenceFlags.AnyDefault : InferenceFlags.None);
19332
+ const typeArgumentTypes = inferTypeArguments(node, candidate, args, getExcludeArgument(args), inferenceContext);
19333
+ return createSignatureInstantiation(candidate, typeArgumentTypes);
19319
19334
}
19320
19335
19321
19336
function getLongestCandidateIndex(candidates: Signature[], argsCount: number): number {
0 commit comments