Explore fewer constraints in getResolvedBaseConstraint (#48613)

This commit is contained in:
Anders Hejlsberg
2022-04-09 07:06:01 -07:00
committed by GitHub
parent b797a3eb2e
commit a744862aa5

View File

@@ -12107,7 +12107,7 @@ namespace ts {
if (type.resolvedBaseConstraint) {
return type.resolvedBaseConstraint;
}
const stack: Type[] = [];
const stack: object[] = [];
return type.resolvedBaseConstraint = getTypeWithThisArgument(getImmediateBaseConstraint(type), type);
function getImmediateBaseConstraint(t: Type): Type {
@@ -12122,8 +12122,9 @@ namespace ts {
// levels of nesting, we are presumably exploring a repeating pattern with a long cycle that hasn't
// yet triggered the deeply nested limiter. We have no test cases that actually get to 50 levels of
// nesting, so it is effectively just a safety stop.
if (stack.length < 10 || stack.length < 50 && !isDeeplyNestedType(t, stack, stack.length)) {
stack.push(t);
const identity = getRecursionIdentity(t);
if (stack.length < 10 || stack.length < 50 && !contains(stack, identity)) {
stack.push(identity);
result = computeBaseConstraint(getSimplifiedType(t, /*writing*/ false));
stack.pop();
}