Skip to content

Commit 0edae12

Browse files
committed
Reduce void | undefined only in conjunction with subtype reduction
1 parent 3fe05c8 commit 0edae12

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/compiler/checker.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -13361,7 +13361,7 @@ namespace ts {
1336113361
return true;
1336213362
}
1336313363

13364-
function removeRedundantLiteralTypes(types: Type[], includes: TypeFlags) {
13364+
function removeRedundantLiteralTypes(types: Type[], includes: TypeFlags, reduceVoidUndefined: boolean) {
1336513365
let i = types.length;
1336613366
while (i > 0) {
1336713367
i--;
@@ -13372,7 +13372,7 @@ namespace ts {
1337213372
flags & TypeFlags.NumberLiteral && includes & TypeFlags.Number ||
1337313373
flags & TypeFlags.BigIntLiteral && includes & TypeFlags.BigInt ||
1337413374
flags & TypeFlags.UniqueESSymbol && includes & TypeFlags.ESSymbol ||
13375-
flags & TypeFlags.Undefined && includes & TypeFlags.Void ||
13375+
reduceVoidUndefined && flags & TypeFlags.Undefined && includes & TypeFlags.Void ||
1337613376
isFreshLiteralType(t) && containsType(types, (<LiteralType>t).regularType);
1337713377
if (remove) {
1337813378
orderedRemoveItemAt(types, i);
@@ -13440,7 +13440,7 @@ namespace ts {
1344013440
}
1344113441
if (unionReduction & (UnionReduction.Literal | UnionReduction.Subtype)) {
1344213442
if (includes & (TypeFlags.Literal | TypeFlags.UniqueESSymbol) || includes & TypeFlags.Void && includes & TypeFlags.Undefined) {
13443-
removeRedundantLiteralTypes(typeSet, includes);
13443+
removeRedundantLiteralTypes(typeSet, includes, !!(unionReduction & UnionReduction.Subtype));
1344413444
}
1344513445
if (includes & TypeFlags.StringLiteral && includes & TypeFlags.TemplateLiteral) {
1344613446
removeStringLiteralsMatchedByTemplateLiterals(typeSet);

0 commit comments

Comments
 (0)