Merge pull request #7377 from Microsoft/port-7373-7163

Ports #7373 and #7163 in release-1.8
This commit is contained in:
Vladimir Matveev 2016-03-03 14:34:12 -08:00
commit 13e845a6b9

View File

@ -6444,8 +6444,10 @@ 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> = {};
inferFromTypes(source, target);
function isInProcess(source: Type, target: Type) {
@ -6571,10 +6573,21 @@ 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;
}
const key = source.id + "," + target.id;
if (hasProperty(visited, key)) {
return;
}
visited[key] = true;
if (depth === 0) {
sourceStack = [];
targetStack = [];