Skip to content

Commit b706a4c

Browse files
committed
Add isDeeplyNestedType logic to getResolvedBaseConstraint
1 parent 66c877f commit b706a4c

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

src/compiler/checker.ts

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10913,9 +10913,12 @@ namespace ts {
1091310913
* circularly references the type variable.
1091410914
*/
1091510915
function getResolvedBaseConstraint(type: InstantiableType | UnionOrIntersectionType): Type {
10916+
if (type.resolvedBaseConstraint) {
10917+
return type.resolvedBaseConstraint;
10918+
}
1091610919
let nonTerminating = false;
10917-
return type.resolvedBaseConstraint ||
10918-
(type.resolvedBaseConstraint = getTypeWithThisArgument(getImmediateBaseConstraint(type), type));
10920+
let stack: Type[] = [];
10921+
return type.resolvedBaseConstraint = getTypeWithThisArgument(getImmediateBaseConstraint(type), type);
1091910922

1092010923
function getImmediateBaseConstraint(t: Type): Type {
1092110924
if (!t.immediateBaseConstraint) {
@@ -10932,9 +10935,14 @@ namespace ts {
1093210935
nonTerminating = true;
1093310936
return t.immediateBaseConstraint = noConstraintType;
1093410937
}
10935-
constraintDepth++;
10936-
let result = computeBaseConstraint(getSimplifiedType(t, /*writing*/ false));
10937-
constraintDepth--;
10938+
let result;
10939+
if (!isDeeplyNestedType(t, stack, stack.length)) {
10940+
stack.push(t);
10941+
constraintDepth++;
10942+
result = computeBaseConstraint(getSimplifiedType(t, /*writing*/ false));
10943+
constraintDepth--;
10944+
stack.pop();
10945+
}
1093810946
if (!popTypeResolution()) {
1093910947
if (t.flags & TypeFlags.TypeParameter) {
1094010948
const errorNode = getConstraintDeclaration(<TypeParameter>t);

0 commit comments

Comments
 (0)