@@ -10397,6 +10397,11 @@ namespace ts {
1039710397 return type;
1039810398 }
1039910399
10400+ function maybeCloneTypeParameter(p: TypeParameter) {
10401+ const constraint = getConstraintOfTypeParameter(p);
10402+ return constraint && maybeTypeOfKind(constraint, TypeFlags.Instantiable | TypeFlags.GenericMappedType) ? cloneTypeParameter(p) : p;
10403+ }
10404+
1040010405 function getConditionalType(root: ConditionalRoot, mapper: TypeMapper | undefined): Type {
1040110406 const checkType = instantiateType(root.checkType, mapper);
1040210407 const extendsType = instantiateType(root.extendsType, mapper);
@@ -10423,11 +10428,14 @@ namespace ts {
1042310428 // * The original `mapper` used to create this conditional
1042410429 // * The mapper that maps the old root type parameter to the clone (`freshMapper`)
1042510430 // * The mapper that maps the clone to its inference result (`context.mapper`)
10426- const freshParams = map(root.inferTypeParameters, cloneTypeParameter );
10431+ const freshParams = map(root.inferTypeParameters, maybeCloneTypeParameter );
1042710432 const freshMapper = createTypeMapper(root.inferTypeParameters, freshParams);
1042810433 const context = createInferenceContext(freshParams, /*signature*/ undefined, InferenceFlags.None);
10434+ const freshCombinedMapper = combineTypeMappers(mapper, freshMapper);
1042910435 for (const p of freshParams) {
10430- p.mapper = combineTypeMappers(mapper, freshMapper);
10436+ if (root.inferTypeParameters.indexOf(p) === -1) {
10437+ p.mapper = freshCombinedMapper;
10438+ }
1043110439 }
1043210440 if (!checkTypeInstantiable) {
1043310441 // We don't want inferences from constraints as they may cause us to eagerly resolve the
0 commit comments