From 1589e4f57e39aa6c5bb9e0be39f60191cf94f8b9 Mon Sep 17 00:00:00 2001 From: Vladimir Matveev Date: Thu, 3 Mar 2016 10:47:21 -0800 Subject: [PATCH] set the maximum depth to explore during type inference --- src/compiler/checker.ts | 6 ++++++ 1 file changed, 6 insertions(+) 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; }