set the maximum depth to explore during type inference

This commit is contained in:
Vladimir Matveev 2016-03-03 10:47:21 -08:00
parent 0f6dbd0250
commit 1589e4f57e

View file

@ -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<boolean> = {};
@ -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;
}