From 0edae127ae68557750b478fd5cf8da8bd2590f62 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Wed, 17 Feb 2021 10:44:09 -1000 Subject: [PATCH] Reduce void | undefined only in conjunction with subtype reduction --- src/compiler/checker.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 85121e6c7c5..834d00ef7e1 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -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--; @@ -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, (t).regularType); if (remove) { orderedRemoveItemAt(types, i); @@ -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);