MCPcopy Index your code
hub / github.com/nodejs/node / isDeeplyNestedType

Function isDeeplyNestedType

test/fixtures/snapshot/typescript.js:67181–67203  ·  view source on GitHub ↗
(type, stack, depth, maxDepth)

Source from the content-addressed store, hash-verified

67179 // has expanded into `[A<NonNullable<NonNullable<NonNullable<NonNullable<NonNullable<T>>>>>>]`. In such cases we need
67180 // to terminate the expansion, and we do so here.
67181 function isDeeplyNestedType(type, stack, depth, maxDepth) {
67182 if (maxDepth === void 0) { maxDepth = 3; }
67183 if (depth >= maxDepth) {
67184 var identity_2 = getRecursionIdentity(type);
67185 var count = 0;
67186 var lastTypeId = 0;
67187 for (var i = 0; i < depth; i++) {
67188 var t = stack[i];
67189 if (getRecursionIdentity(t) === identity_2) {
67190 // We only count occurrences with a higher type id than the previous occurrence, since higher
67191 // type ids are an indicator of newer instantiations caused by recursion.
67192 if (t.id >= lastTypeId) {
67193 count++;
67194 if (count >= maxDepth) {
67195 return true;
67196 }
67197 }
67198 lastTypeId = t.id;
67199 }
67200 }
67201 }
67202 return false;
67203 }
67204 // The recursion identity of a type is an object identity that is shared among multiple instantiations of the type.
67205 // We track recursion identities in order to identify deeply nested and possibly infinite type instantiations with
67206 // the same origin. For example, when type parameters are in scope in an object type such as { x: T }, all

Callers 2

recursiveTypeRelatedToFunction · 0.85
structuredTypeRelatedToFunction · 0.85

Calls 1

getRecursionIdentityFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…