Reduce void | undefined only in conjunction with subtype reduction (#42846)

* Reduce void | undefined only in conjunction with subtype reduction

* Accept new baselines

* Add regression test
This commit is contained in:
Anders Hejlsberg
2021-02-17 14:48:07 -10:00
committed by GitHub
parent d640313ff2
commit 412ecbc291
16 changed files with 129 additions and 23 deletions
+3 -3
View File
@@ -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, (<LiteralType>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);