Skip to content

Commit c9a3ea6

Browse files
committed
Stop analyzing loop branches when declared type is seen
1 parent 89506c1 commit c9a3ea6

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

src/compiler/checker.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7780,16 +7780,15 @@ namespace ts {
77807780
if (cache[key]) {
77817781
return cache[key];
77827782
}
7783-
// If the type at a particular antecedent path is the declared type and the
7784-
// reference is known to always be assigned (i.e. when declared and initial types
7785-
// are the same), there is no reason to process more antecedents since the only
7786-
// possible outcome is subtypes that will be removed in the final union type anyway.
7787-
if (type === declaredType && declaredType === initialType) {
7788-
return cache[key] = type;
7789-
}
77907783
if (!contains(antecedentTypes, type)) {
77917784
antecedentTypes.push(type);
77927785
}
7786+
// If the type at a particular antecedent path is the declared type there is no
7787+
// reason to process more antecedents since the only possible outcome is subtypes
7788+
// that will be removed in the final union type anyway.
7789+
if (type === declaredType) {
7790+
break;
7791+
}
77937792
}
77947793
return cache[key] = getUnionType(antecedentTypes);
77957794
}

0 commit comments

Comments
 (0)