Skip to content

Commit

Permalink
Reduce void | undefined only in conjunction with subtype reduction
Browse files Browse the repository at this point in the history
  • Loading branch information
ahejlsberg committed Feb 17, 2021
1 parent 3fe05c8 commit 0edae12
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/compiler/checker.ts
Expand Up @@ -13361,7 +13361,7 @@ namespace ts {
return true;
}

function removeRedundantLiteralTypes(types: Type[], includes: TypeFlags) {
function removeRedundantLiteralTypes(types: Type[], includes: TypeFlags, reduceVoidUndefined: boolean) {
let i = types.length;
while (i > 0) {
i--;
Expand All @@ -13372,7 +13372,7 @@ namespace ts {
flags & TypeFlags.NumberLiteral && includes & TypeFlags.Number ||
flags & TypeFlags.BigIntLiteral && includes & TypeFlags.BigInt ||
flags & TypeFlags.UniqueESSymbol && includes & TypeFlags.ESSymbol ||
flags & TypeFlags.Undefined && includes & TypeFlags.Void ||
reduceVoidUndefined && flags & TypeFlags.Undefined && includes & TypeFlags.Void ||
isFreshLiteralType(t) && containsType(types, (<LiteralType>t).regularType);
if (remove) {
orderedRemoveItemAt(types, i);
Expand Down Expand Up @@ -13440,7 +13440,7 @@ namespace ts {
}
if (unionReduction & (UnionReduction.Literal | UnionReduction.Subtype)) {
if (includes & (TypeFlags.Literal | TypeFlags.UniqueESSymbol) || includes & TypeFlags.Void && includes & TypeFlags.Undefined) {
removeRedundantLiteralTypes(typeSet, includes);
removeRedundantLiteralTypes(typeSet, includes, !!(unionReduction & UnionReduction.Subtype));
}
if (includes & TypeFlags.StringLiteral && includes & TypeFlags.TemplateLiteral) {
removeStringLiteralsMatchedByTemplateLiterals(typeSet);
Expand Down

0 comments on commit 0edae12

Please sign in to comment.