@@ -12719,7 +12719,7 @@ namespace ts {
12719
12719
if (!(inferredExtendsType.flags & TypeFlags.AnyOrUnknown) && (checkType.flags & TypeFlags.Any || !isTypeAssignableTo(getPermissiveInstantiation(checkType), getPermissiveInstantiation(inferredExtendsType)))) {
12720
12720
// Return union of trueType and falseType for 'any' since it matches anything
12721
12721
if (checkType.flags & TypeFlags.Any) {
12722
- (extraTypes || (extraTypes = [])).push(instantiateType (root.trueType, combinedMapper || mapper));
12722
+ (extraTypes || (extraTypes = [])).push(instantiateTypeWithoutDepthIncrease (root.trueType, combinedMapper || mapper));
12723
12723
}
12724
12724
// If falseType is an immediately nested conditional type that isn't distributive or has an
12725
12725
// identical checkType, switch to that type and loop.
@@ -12731,7 +12731,7 @@ namespace ts {
12731
12731
continue;
12732
12732
}
12733
12733
}
12734
- result = instantiateType (falseType, mapper);
12734
+ result = instantiateTypeWithoutDepthIncrease (falseType, mapper);
12735
12735
break;
12736
12736
}
12737
12737
// Return trueType for a definitely true extends check. We check instantiations of the two
@@ -12740,7 +12740,7 @@ namespace ts {
12740
12740
// type Foo<T extends { x: any }> = T extends { x: string } ? string : number
12741
12741
// doesn't immediately resolve to 'string' instead of being deferred.
12742
12742
if (inferredExtendsType.flags & TypeFlags.AnyOrUnknown || isTypeAssignableTo(getRestrictiveInstantiation(checkType), getRestrictiveInstantiation(inferredExtendsType))) {
12743
- result = instantiateType (root.trueType, combinedMapper || mapper);
12743
+ result = instantiateTypeWithoutDepthIncrease (root.trueType, combinedMapper || mapper);
12744
12744
break;
12745
12745
}
12746
12746
}
@@ -13720,6 +13720,17 @@ namespace ts {
13720
13720
return result;
13721
13721
}
13722
13722
13723
+ /**
13724
+ * This can be used to avoid the penalty on instantiation depth for types which result from immediate
13725
+ * simplification. It essentially removes the depth increase done in `instantiateType`.
13726
+ */
13727
+ function instantiateTypeWithoutDepthIncrease(type: Type, mapper: TypeMapper | undefined) {
13728
+ instantiationDepth--;
13729
+ const result = instantiateType(type, mapper);
13730
+ instantiationDepth++;
13731
+ return result;
13732
+ }
13733
+
13723
13734
function instantiateTypeWorker(type: Type, mapper: TypeMapper): Type {
13724
13735
const flags = type.flags;
13725
13736
if (flags & TypeFlags.TypeParameter) {
0 commit comments