TypeFlags enum contains bit flags that classify types in the TypeScript type system. Every Type object has a flags property containing a combination of these flags.
Primitive Type Flags
Basic Types
| Flag | Description |
|---|---|
Any | any type |
Unknown | unknown type |
Undefined | undefined type |
Null | null type |
Void | void type |
String | string type |
Number | number type |
BigInt | bigint type |
Boolean | boolean type |
ESSymbol | symbol type |
Never | never type |
Literal Types
| Flag | Description |
|---|---|
StringLiteral | String literal type (e.g., "hello") |
NumberLiteral | Number literal type (e.g., 42) |
BigIntLiteral | BigInt literal type (e.g., 100n) |
BooleanLiteral | Boolean literal type (true or false) |
UniqueESSymbol | Unique symbol type |
EnumLiteral | Enum member literal |
Enum | Computed enum member value |
Complex Type Flags
Object and Structure Types
| Flag | Description | |
|---|---|---|
Object | Object type | |
NonPrimitive | object intrinsic type | |
TypeParameter | Type parameter | |
Union | Union type (`T | U`) |
Intersection | Intersection type (T & U) |
Advanced Types
| Flag | Description |
|---|---|
Index | keyof T type |
IndexedAccess | T[K] type |
Conditional | Conditional type (T extends U ? X : Y) |
Substitution | Type parameter substitution |
TemplateLiteral | Template literal type |
StringMapping | String mapping type (e.g., Uppercase<T>) |
Composite Flags
The enum includes composite flags for common type combinations:Nullable Types
undefined or null.
Literal Types
Unit Types
String-like Types
Number-like Types
Boolean-like Types
Primitive Types
Structured Types
Type Variables
Instantiable Types
Union and Intersection
Structured or Instantiable
Specialized Composite Flags
Possibly Falsy
Narrowable Types
null, undefined, void, and never).
Definitely Non-Nullable
null or undefined.
Using TypeFlags
Checking Type Flags
Testing Multiple Flags
Type Guards
Combine flags with type narrowing:Common Patterns
Checking for Nullable Types
Distinguishing Primitives
Working with Literals
Handling Unions and Intersections
Internal Flags
Some flags are marked as internal and used by the compiler:See Also
- Node Types - AST node types
- SymbolFlags - Symbol classification flags
- Type Checker API - Working with types