@@ -65,6 +65,7 @@ namespace ts {
65
65
let typeCount = 0;
66
66
let symbolCount = 0;
67
67
let enumCount = 0;
68
+ let instantiationCount = 0;
68
69
let instantiationDepth = 0;
69
70
let constraintDepth = 0;
70
71
let currentNode: Node | undefined;
@@ -11408,13 +11409,14 @@ namespace ts {
11408
11409
if (!type || !mapper || mapper === identityMapper) {
11409
11410
return type;
11410
11411
}
11411
- if (instantiationDepth === 50) {
11412
+ if (instantiationDepth === 50 || instantiationCount >= 5000000 ) {
11412
11413
// We have reached 50 recursive type instantiations and there is a very high likelyhood we're dealing
11413
11414
// with a combination of infinite generic types that perpetually generate new type identities. We stop
11414
11415
// the recursion here by yielding the error type.
11415
11416
error(currentNode, Diagnostics.Type_instantiation_is_excessively_deep_and_possibly_infinite);
11416
11417
return errorType;
11417
11418
}
11419
+ instantiationCount++;
11418
11420
instantiationDepth++;
11419
11421
const result = instantiateTypeWorker(type, mapper);
11420
11422
instantiationDepth--;
@@ -24494,6 +24496,7 @@ namespace ts {
24494
24496
function checkExpression(node: Expression | QualifiedName, checkMode?: CheckMode, forceTuple?: boolean): Type {
24495
24497
const saveCurrentNode = currentNode;
24496
24498
currentNode = node;
24499
+ instantiationCount = 0;
24497
24500
const uninstantiatedType = checkExpressionWorker(node, checkMode, forceTuple);
24498
24501
const type = instantiateTypeWithSingleGenericCallSignature(node, uninstantiatedType, checkMode);
24499
24502
if (isConstEnumObjectType(type)) {
@@ -29204,6 +29207,7 @@ namespace ts {
29204
29207
if (node) {
29205
29208
const saveCurrentNode = currentNode;
29206
29209
currentNode = node;
29210
+ instantiationCount = 0;
29207
29211
checkSourceElementWorker(node);
29208
29212
currentNode = saveCurrentNode;
29209
29213
}
@@ -29475,6 +29479,7 @@ namespace ts {
29475
29479
function checkDeferredNode(node: Node) {
29476
29480
const saveCurrentNode = currentNode;
29477
29481
currentNode = node;
29482
+ instantiationCount = 0;
29478
29483
switch (node.kind) {
29479
29484
case SyntaxKind.FunctionExpression:
29480
29485
case SyntaxKind.ArrowFunction:
0 commit comments