Skip to content

Commit b75a90e

Browse files
committed
Return type inference should not include parameter inferences
1 parent 38f3b05 commit b75a90e

File tree

1 file changed

+6
-9
lines changed

1 file changed

+6
-9
lines changed

src/compiler/checker.ts

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14864,13 +14864,6 @@ namespace ts {
1486414864
return context && createInferenceContextWorker(map(context.inferences, cloneInferenceInfo), context.signature, context.flags | extraFlags, context.compareTypes);
1486514865
}
1486614866

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-
1487414867
function createInferenceContextWorker(inferences: InferenceInfo[], signature: Signature | undefined, flags: InferenceFlags, compareTypes: TypeComparer): InferenceContext {
1487514868
const context: InferenceContext = {
1487614869
inferences,
@@ -20846,7 +20839,8 @@ namespace ts {
2084620839
// We clone the inference context to avoid disturbing a resolution in progress for an
2084720840
// outer call expression. Effectively we just want a snapshot of whatever has been
2084820841
// 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));
2085020844
const instantiatedType = instantiateType(contextualType, outerMapper);
2085120845
// If the contextual type is a generic function type with a single call signature, we
2085220846
// instantiate the type with its own type parameters and type arguments. This ensures that
@@ -20864,7 +20858,10 @@ namespace ts {
2086420858
inferTypes(context.inferences, inferenceSourceType, inferenceTargetType, InferencePriority.ReturnType);
2086520859
// Create a type mapper for instantiating generic contextual types using the inferences made
2086620860
// 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;
2086820865
}
2086920866
}
2087020867

0 commit comments

Comments
 (0)