mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00:00
Stop analyzing loop branches when declared type is seen
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user