mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-16 15:45:27 -05:00
Properly check whether union type contains only primitive types (#46645)
* Properly check whether union type contains only primitive types * Add regression test * Remove 'export' modifier from test
This commit is contained in:
@@ -14153,6 +14153,7 @@ namespace ts {
|
||||
// We ignore 'never' types in unions
|
||||
if (!(flags & TypeFlags.Never)) {
|
||||
includes |= flags & TypeFlags.IncludesMask;
|
||||
if (flags & TypeFlags.Instantiable) includes |= TypeFlags.IncludesInstantiable;
|
||||
if (type === wildcardType) includes |= TypeFlags.IncludesWildcard;
|
||||
if (!strictNullChecks && flags & TypeFlags.Nullable) {
|
||||
if (!(getObjectFlags(type) & ObjectFlags.ContainsWideningType)) includes |= TypeFlags.IncludesNonWideningType;
|
||||
|
||||
@@ -5187,8 +5187,6 @@ namespace ts {
|
||||
// 'Narrowable' types are types where narrowing actually narrows.
|
||||
// This *should* be every type other than null, undefined, void, and never
|
||||
Narrowable = Any | Unknown | StructuredOrInstantiable | StringLike | NumberLike | BigIntLike | BooleanLike | ESSymbol | UniqueESSymbol | NonPrimitive,
|
||||
/* @internal */
|
||||
NotPrimitiveUnion = Any | Unknown | Enum | Void | Never | Object | Intersection | Instantiable,
|
||||
// The following flags are aggregated during union and intersection type construction
|
||||
/* @internal */
|
||||
IncludesMask = Any | Unknown | Primitive | Never | Object | Union | Intersection | NonPrimitive | TemplateLiteral,
|
||||
@@ -5201,6 +5199,10 @@ namespace ts {
|
||||
IncludesWildcard = IndexedAccess,
|
||||
/* @internal */
|
||||
IncludesEmptyObject = Conditional,
|
||||
/* @internal */
|
||||
IncludesInstantiable = Substitution,
|
||||
/* @internal */
|
||||
NotPrimitiveUnion = Any | Unknown | Enum | Void | Never | Object | Intersection | IncludesInstantiable,
|
||||
}
|
||||
|
||||
export type DestructuringPattern = BindingPattern | ObjectLiteralExpression | ArrayLiteralExpression;
|
||||
|
||||
Reference in New Issue
Block a user