Stop analyzing loop branches when declared type is seen

This commit is contained in:
Anders Hejlsberg 2016-05-11 12:49:42 -07:00
parent 89506c1138
commit c9a3ea6fe0

View File

@ -7780,16 +7780,15 @@ namespace ts {
if (cache[key]) {
return cache[key];
}
// If the type at a particular antecedent path is the declared type and the
// reference is known to always be assigned (i.e. when declared and initial types
// are the same), there is no reason to process more antecedents since the only
// possible outcome is subtypes that will be removed in the final union type anyway.
if (type === declaredType && declaredType === initialType) {
return cache[key] = type;
}
if (!contains(antecedentTypes, type)) {
antecedentTypes.push(type);
}
// If the type at a particular antecedent path is the declared type there is no
// reason to process more antecedents since the only possible outcome is subtypes
// that will be removed in the final union type anyway.
if (type === declaredType) {
break;
}
}
return cache[key] = getUnionType(antecedentTypes);
}