mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-05 16:54:54 -05:00
Remove more intersections with empty value domains from union types
This commit is contained in:
@@ -7917,8 +7917,13 @@ namespace ts {
|
||||
return binarySearch(types, type, getTypeId, compareValues) >= 0;
|
||||
}
|
||||
|
||||
// Return true if the given intersection type contains (a) more than one unit type or (b) an object
|
||||
// type and a nullable type (null or undefined).
|
||||
// Return true if the given intersection type contains
|
||||
// more than one unit type or,
|
||||
// an object type and a nullable type (null or undefined), or
|
||||
// a string-like type and a non-string-like primitive type, or
|
||||
// a number-like type and a non-number-like primitive type, or
|
||||
// a symbol-like type and a non-symbol-like primitive type, or
|
||||
// a void-like type and a non-void-like primitive type.
|
||||
function isEmptyIntersectionType(type: IntersectionType) {
|
||||
let combined: TypeFlags = 0;
|
||||
for (const t of type.types) {
|
||||
@@ -7926,7 +7931,11 @@ namespace ts {
|
||||
return true;
|
||||
}
|
||||
combined |= t.flags;
|
||||
if (combined & TypeFlags.Nullable && combined & (TypeFlags.Object | TypeFlags.NonPrimitive)) {
|
||||
if (combined & TypeFlags.Nullable && combined & (TypeFlags.Object | TypeFlags.NonPrimitive) ||
|
||||
combined & TypeFlags.StringLike && combined & (TypeFlags.Primitive & ~TypeFlags.StringLike) ||
|
||||
combined & TypeFlags.NumberLike && combined & (TypeFlags.Primitive & ~TypeFlags.NumberLike) ||
|
||||
combined & TypeFlags.ESSymbolLike && combined & (TypeFlags.Primitive & ~TypeFlags.ESSymbolLike) ||
|
||||
combined & TypeFlags.VoidLike && combined & (TypeFlags.Primitive & ~TypeFlags.VoidLike)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3613,6 +3613,7 @@ namespace ts {
|
||||
BooleanLike = Boolean | BooleanLiteral,
|
||||
EnumLike = Enum | EnumLiteral,
|
||||
ESSymbolLike = ESSymbol | UniqueESSymbol,
|
||||
VoidLike = Void | Undefined,
|
||||
UnionOrIntersection = Union | Intersection,
|
||||
StructuredType = Object | Union | Intersection,
|
||||
TypeVariable = TypeParameter | IndexedAccess,
|
||||
|
||||
Reference in New Issue
Block a user