Skip to content

Commit d90d6b9

Browse files
committed
Remove more intersections with empty value domains from union types
1 parent ef8d509 commit d90d6b9

2 files changed

Lines changed: 13 additions & 3 deletions

File tree

src/compiler/checker.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7917,16 +7917,25 @@ namespace ts {
79177917
return binarySearch(types, type, getTypeId, compareValues) >= 0;
79187918
}
79197919

7920-
// Return true if the given intersection type contains (a) more than one unit type or (b) an object
7921-
// type and a nullable type (null or undefined).
7920+
// Return true if the given intersection type contains
7921+
// more than one unit type or,
7922+
// an object type and a nullable type (null or undefined), or
7923+
// a string-like type and a non-string-like primitive type, or
7924+
// a number-like type and a non-number-like primitive type, or
7925+
// a symbol-like type and a non-symbol-like primitive type, or
7926+
// a void-like type and a non-void-like primitive type.
79227927
function isEmptyIntersectionType(type: IntersectionType) {
79237928
let combined: TypeFlags = 0;
79247929
for (const t of type.types) {
79257930
if (t.flags & TypeFlags.Unit && combined & TypeFlags.Unit) {
79267931
return true;
79277932
}
79287933
combined |= t.flags;
7929-
if (combined & TypeFlags.Nullable && combined & (TypeFlags.Object | TypeFlags.NonPrimitive)) {
7934+
if (combined & TypeFlags.Nullable && combined & (TypeFlags.Object | TypeFlags.NonPrimitive) ||
7935+
combined & TypeFlags.StringLike && combined & (TypeFlags.Primitive & ~TypeFlags.StringLike) ||
7936+
combined & TypeFlags.NumberLike && combined & (TypeFlags.Primitive & ~TypeFlags.NumberLike) ||
7937+
combined & TypeFlags.ESSymbolLike && combined & (TypeFlags.Primitive & ~TypeFlags.ESSymbolLike) ||
7938+
combined & TypeFlags.VoidLike && combined & (TypeFlags.Primitive & ~TypeFlags.VoidLike)) {
79307939
return true;
79317940
}
79327941
}

src/compiler/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3613,6 +3613,7 @@ namespace ts {
36133613
BooleanLike = Boolean | BooleanLiteral,
36143614
EnumLike = Enum | EnumLiteral,
36153615
ESSymbolLike = ESSymbol | UniqueESSymbol,
3616+
VoidLike = Void | Undefined,
36163617
UnionOrIntersection = Union | Intersection,
36173618
StructuredType = Object | Union | Intersection,
36183619
TypeVariable = TypeParameter | IndexedAccess,

0 commit comments

Comments
 (0)