@@ -10397,6 +10397,11 @@ namespace ts {
10397
10397
return type;
10398
10398
}
10399
10399
10400
+ function maybeCloneTypeParameter(p: TypeParameter) {
10401
+ const constraint = getConstraintOfTypeParameter(p);
10402
+ return constraint && maybeTypeOfKind(constraint, TypeFlags.Instantiable | TypeFlags.GenericMappedType) ? cloneTypeParameter(p) : p;
10403
+ }
10404
+
10400
10405
function getConditionalType(root: ConditionalRoot, mapper: TypeMapper | undefined): Type {
10401
10406
const checkType = instantiateType(root.checkType, mapper);
10402
10407
const extendsType = instantiateType(root.extendsType, mapper);
@@ -10423,11 +10428,14 @@ namespace ts {
10423
10428
// * The original `mapper` used to create this conditional
10424
10429
// * The mapper that maps the old root type parameter to the clone (`freshMapper`)
10425
10430
// * 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 );
10427
10432
const freshMapper = createTypeMapper(root.inferTypeParameters, freshParams);
10428
10433
const context = createInferenceContext(freshParams, /*signature*/ undefined, InferenceFlags.None);
10434
+ const freshCombinedMapper = combineTypeMappers(mapper, freshMapper);
10429
10435
for (const p of freshParams) {
10430
- p.mapper = combineTypeMappers(mapper, freshMapper);
10436
+ if (root.inferTypeParameters.indexOf(p) === -1) {
10437
+ p.mapper = freshCombinedMapper;
10438
+ }
10431
10439
}
10432
10440
if (!checkTypeInstantiable) {
10433
10441
// We don't want inferences from constraints as they may cause us to eagerly resolve the
0 commit comments