Skip to content

Commit 744e510

Browse files
committed
Merge pull request #7373 from Microsoft/limitInferenceDepth
set the maximum depth to explore during type inference
2 parents 24c47f1 + 1589e4f commit 744e510

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

src/compiler/checker.ts

+6
Original file line numberDiff line numberDiff line change
@@ -6585,6 +6585,7 @@ namespace ts {
65856585
function inferTypes(context: InferenceContext, source: Type, target: Type) {
65866586
let sourceStack: Type[];
65876587
let targetStack: Type[];
6588+
const maxDepth = 5;
65886589
let depth = 0;
65896590
let inferiority = 0;
65906591
const visited: Map<boolean> = {};
@@ -6713,6 +6714,11 @@ namespace ts {
67136714
if (isInProcess(source, target)) {
67146715
return;
67156716
}
6717+
// we delibirately limit the depth we examine to infer types: this speeds up the overall inference process
6718+
// and user rarely expects inferences to be made from the deeply nested constituents.
6719+
if (depth > maxDepth) {
6720+
return;
6721+
}
67166722
if (isDeeplyNestedGeneric(source, sourceStack, depth) && isDeeplyNestedGeneric(target, targetStack, depth)) {
67176723
return;
67186724
}

0 commit comments

Comments
 (0)