@@ -14864,13 +14864,6 @@ namespace ts {
14864
14864
return context && createInferenceContextWorker(map(context.inferences, cloneInferenceInfo), context.signature, context.flags | extraFlags, context.compareTypes);
14865
14865
}
14866
14866
14867
- function cloneInferredPartOfContext(context: InferenceContext): InferenceContext | undefined {
14868
- const inferences = filter(context.inferences, hasInferenceCandidates);
14869
- return inferences.length ?
14870
- createInferenceContextWorker(map(inferences, cloneInferenceInfo), context.signature, context.flags, context.compareTypes) :
14871
- undefined;
14872
- }
14873
-
14874
14867
function createInferenceContextWorker(inferences: InferenceInfo[], signature: Signature | undefined, flags: InferenceFlags, compareTypes: TypeComparer): InferenceContext {
14875
14868
const context: InferenceContext = {
14876
14869
inferences,
@@ -20846,7 +20839,8 @@ namespace ts {
20846
20839
// We clone the inference context to avoid disturbing a resolution in progress for an
20847
20840
// outer call expression. Effectively we just want a snapshot of whatever has been
20848
20841
// inferred for any outer call expression so far.
20849
- const outerMapper = getMapperFromContext(cloneInferenceContext(getInferenceContext(node), InferenceFlags.NoDefault));
20842
+ const outerContext = getInferenceContext(node);
20843
+ const outerMapper = getMapperFromContext(cloneInferenceContext(outerContext, InferenceFlags.NoDefault));
20850
20844
const instantiatedType = instantiateType(contextualType, outerMapper);
20851
20845
// If the contextual type is a generic function type with a single call signature, we
20852
20846
// instantiate the type with its own type parameters and type arguments. This ensures that
@@ -20864,7 +20858,10 @@ namespace ts {
20864
20858
inferTypes(context.inferences, inferenceSourceType, inferenceTargetType, InferencePriority.ReturnType);
20865
20859
// Create a type mapper for instantiating generic contextual types using the inferences made
20866
20860
// from the return type.
20867
- context.returnMapper = getMapperFromContext(cloneInferredPartOfContext(context));
20861
+ const returnContext = createInferenceContext(signature.typeParameters!, signature, context.flags);
20862
+ const returnSourceType = instantiateType(contextualType, outerContext && outerContext.returnMapper);
20863
+ inferTypes(returnContext.inferences, returnSourceType, inferenceTargetType);
20864
+ context.returnMapper = some(returnContext.inferences, hasInferenceCandidates) ? getMapperFromContext(returnContext) : undefined;
20868
20865
}
20869
20866
}
20870
20867
0 commit comments