@@ -20403,10 +20403,10 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
2040320403
2040420404 /**
2040520405 * Return a type mapper that combines the context's return mapper with a mapper that erases any additional type parameters
20406- * to their constraints .
20406+ * to their inferences at the time of creation .
2040720407 */
2040820408 function createOuterReturnMapper(context: InferenceContext) {
20409- return mergeTypeMappers( context.returnMapper, createInferenceContext(map(context.inferences, i => i.typeParameter), context.signature, context.flags, context.compareTypes ).mapper);
20409+ return context.outerReturnMapper ??= mergeTypeMappers( context.returnMapper, cloneInferenceContext( context).mapper);
2041020410 }
2041120411
2041220412 function combineTypeMappers(mapper1: TypeMapper | undefined, mapper2: TypeMapper): TypeMapper {
@@ -35550,9 +35550,9 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
3555035550 // the source type uses the outer context's return mapper (which excludes inferences made from
3555135551 // outer arguments), and (b) we don't want any further inferences going into this context.
3555235552 // We use `createOuterReturnMapper` to ensure that all occurrences of outer type parameters are
35553- // replaced with either inferences produced from the outer return type or constraints of those
35554- // type parameters. This protects against circular inferences, i.e. avoiding situations where
35555- // inferences reference type parameters for which the inferences are being made.
35553+ // replaced with inferences produced from the outer return type or preceding outer arguments.
35554+ // This protects against circular inferences, i.e. avoiding situations where inferences reference
35555+ // type parameters for which the inferences are being made.
3555635556 const returnContext = createInferenceContext(signature.typeParameters!, signature, context.flags);
3555735557 const returnSourceType = instantiateType(contextualType, outerContext && createOuterReturnMapper(outerContext));
3555835558 inferTypes(returnContext.inferences, returnSourceType, inferenceTargetType);
0 commit comments