@@ -9155,8 +9155,15 @@ namespace ts {
9155
9155
return constraint && maybeTypeOfKind(constraint, TypeFlags.Primitive | TypeFlags.Index);
9156
9156
}
9157
9157
9158
+ function getSuppliedType(context: InferenceContext, index: number): Type | undefined {
9159
+ if (context.suppliedTypes && index < context.suppliedTypes.length) {
9160
+ return context.inferredTypes[index] = context.suppliedTypes[index];
9161
+ }
9162
+ return undefined;
9163
+ }
9164
+
9158
9165
function getInferredType(context: InferenceContext, index: number): Type {
9159
- let inferredType = context.inferredTypes[index];
9166
+ let inferredType = context.inferredTypes[index] || getSuppliedType(context, index) ;
9160
9167
let inferenceSucceeded: boolean;
9161
9168
if (!inferredType) {
9162
9169
const inferences = getInferenceCandidates(context, index);
@@ -13410,6 +13417,7 @@ namespace ts {
13410
13417
}
13411
13418
}
13412
13419
13420
+ const numTypeArguments = typeArguments ? typeArguments.length : 0;
13413
13421
const candidates = candidatesOutArray || [];
13414
13422
// reorderCandidates fills up the candidates array directly
13415
13423
reorderCandidates(signatures, candidates);
@@ -13580,28 +13588,26 @@ namespace ts {
13580
13588
? createInferenceContext(originalCandidate, /*inferUnionTypes*/ false)
13581
13589
: undefined;
13582
13590
13583
- // fix each supplied type argument in the inference context
13584
- if (typeArguments) {
13585
- for (let i = 0; i < typeArguments.length; i++) {
13586
- inferenceContext.inferredTypes[i] = getTypeFromTypeNode(typeArguments[i]);
13587
- inferenceContext.inferences[i].isFixed = true;
13588
- }
13589
- }
13590
-
13591
13591
while (true) {
13592
13592
candidate = originalCandidate;
13593
13593
if (candidate.typeParameters) {
13594
- // Check any supplied type arguments against the candidate.
13595
- typeArgumentsAreValid = !typeArguments || checkTypeArguments(candidate, typeArguments, inferenceContext.inferredTypes, /*reportErrors*/ false);
13596
- if (typeArgumentsAreValid) {
13594
+ let typeArgumentTypes: Type[] | undefined;
13595
+ if (typeArguments) {
13596
+ // Check any supplied type arguments against the candidate.
13597
+ typeArgumentTypes = map(typeArguments, getTypeFromTypeNode)
13598
+ typeArgumentsAreValid = checkTypeArguments(candidate, typeArguments, typeArgumentTypes, /*reportErrors*/ false);
13599
+ }
13600
+ if ((!typeArguments || typeArgumentsAreValid) && numTypeArguments < candidate.typeParameters.length) {
13597
13601
// Infer any unsupplied type arguments for the candidate.
13602
+ inferenceContext.suppliedTypes = typeArgumentTypes;
13598
13603
inferTypeArguments(node, candidate, args, excludeArgument, inferenceContext);
13599
13604
typeArgumentsAreValid = inferenceContext.failedTypeParameterIndex === undefined;
13605
+ typeArgumentTypes = inferenceContext.inferredTypes;
13600
13606
}
13601
13607
if (!typeArgumentsAreValid) {
13602
13608
break;
13603
13609
}
13604
- candidate = getSignatureInstantiation(candidate, inferenceContext.inferredTypes );
13610
+ candidate = getSignatureInstantiation(candidate, typeArgumentTypes );
13605
13611
}
13606
13612
if (!checkApplicableSignature(node, args, candidate, relation, excludeArgument, /*reportErrors*/ false)) {
13607
13613
break;
0 commit comments