Skip to content

Commit 3712faa

Browse files
committed
Handle nested distributive types with different checkType
1 parent c386451 commit 3712faa

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

src/compiler/checker.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12721,11 +12721,15 @@ namespace ts {
1272112721
if (checkType.flags & TypeFlags.Any) {
1272212722
(extraTypes || (extraTypes = [])).push(instantiateType(root.trueType, combinedMapper || mapper));
1272312723
}
12724-
// If falseType is an immediately nested conditional type, switch to that type and loop.
12724+
// If falseType is an immediately nested conditional type that isn't distributive or has an
12725+
// identical checkType, switch to that type and loop.
1272512726
const falseType = root.falseType;
12726-
if (falseType.flags & TypeFlags.Conditional && (<ConditionalType>falseType).root.node.parent === root.node) {
12727-
root = (<ConditionalType>falseType).root;
12728-
continue;
12727+
if (falseType.flags & TypeFlags.Conditional) {
12728+
const newRoot = (<ConditionalType>falseType).root;
12729+
if (newRoot.node.parent === root.node && (!newRoot.isDistributive || newRoot.checkType === root.checkType)) {
12730+
root = newRoot;
12731+
continue;
12732+
}
1272912733
}
1273012734
result = instantiateType(falseType, mapper);
1273112735
break;

0 commit comments

Comments
 (0)