From a744862aa58bfa890ec95098febc680380d34108 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Sat, 9 Apr 2022 07:06:01 -0700 Subject: [PATCH] Explore fewer constraints in getResolvedBaseConstraint (#48613) --- src/compiler/checker.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 2e8f0ff2ae6..26299645537 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -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(); }