diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 4ca97793073..835fc343f8d 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -6585,6 +6585,7 @@ namespace ts { function inferTypes(context: InferenceContext, source: Type, target: Type) { let sourceStack: Type[]; let targetStack: Type[]; + const maxDepth = 5; let depth = 0; let inferiority = 0; const visited: Map = {}; @@ -6713,6 +6714,11 @@ namespace ts { if (isInProcess(source, target)) { return; } + // we delibirately limit the depth we examine to infer types: this speeds up the overall inference process + // and user rarely expects inferences to be made from the deeply nested constituents. + if (depth > maxDepth) { + return; + } if (isDeeplyNestedGeneric(source, sourceStack, depth) && isDeeplyNestedGeneric(target, targetStack, depth)) { return; }