Skip to content

Commit 13e845a

Browse files
committed
Merge pull request #7377 from Microsoft/port-7373-7163
Ports #7373 and #7163 in release-1.8
2 parents 243440a + 365e544 commit 13e845a

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/compiler/checker.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6444,8 +6444,10 @@ namespace ts {
64446444
function inferTypes(context: InferenceContext, source: Type, target: Type) {
64456445
let sourceStack: Type[];
64466446
let targetStack: Type[];
6447+
const maxDepth = 5;
64476448
let depth = 0;
64486449
let inferiority = 0;
6450+
const visited: Map<boolean> = {};
64496451
inferFromTypes(source, target);
64506452

64516453
function isInProcess(source: Type, target: Type) {
@@ -6571,10 +6573,21 @@ namespace ts {
65716573
if (isInProcess(source, target)) {
65726574
return;
65736575
}
6576+
// we delibirately limit the depth we examine to infer types: this speeds up the overall inference process
6577+
// and user rarely expects inferences to be made from the deeply nested constituents.
6578+
if (depth > maxDepth) {
6579+
return;
6580+
}
65746581
if (isDeeplyNestedGeneric(source, sourceStack, depth) && isDeeplyNestedGeneric(target, targetStack, depth)) {
65756582
return;
65766583
}
65776584

6585+
const key = source.id + "," + target.id;
6586+
if (hasProperty(visited, key)) {
6587+
return;
6588+
}
6589+
visited[key] = true;
6590+
65786591
if (depth === 0) {
65796592
sourceStack = [];
65806593
targetStack = [];

0 commit comments

Comments
 (0)