A heterogeneous enum in TypeScript is an enumeration that contains a mixture of both string and numeric member values. It combines the distinct compilation behaviors and type-checking rules of both numeric and string enums within a single data structure.Documentation Index
Fetch the complete documentation index at: https://docs.syntblaze.com/llms.txt
Use this file to discover all available pages before exploring further.
Initialization Rules
The TypeScript compiler enforces strict initialization rules when mixing types within an enum:- String Members: Must be explicitly initialized with a string literal.
- Numeric Members: Can be explicitly initialized or implicitly auto-incremented.
- Positional Dependency: If an uninitialized member immediately follows a string member, the compiler will throw an error (
TS1061: Enum member must have initializer). Auto-incrementing is only valid if the preceding member resolves to a numeric value.
Reverse Mapping Behavior
TypeScript handles the transpilation of string and numeric enum members differently. Numeric enums generate a reverse mapping (value-to-key) in the emitted JavaScript, whereas string enums only generate a forward mapping (key-to-value). In a heterogeneous enum, the compiler applies these rules on a per-member basis. Only the numeric members will populate the reverse mapping object. TypeScript Source:Status object at runtime, it evaluates to:
Type Resolution
At the type level, a heterogeneous enum creates a union type of its unique, opaque members (Config.Path | Config.Timeout). TypeScript treats string enum members as nominal types. This means the raw string literal "/usr/bin" is not assignable to Config.Path, and the enum’s underlying type is not structurally equivalent to a standard literal union like "/usr/bin" | 5000.
When assigning enum members to variables, TypeScript’s type inference behaves differently depending on the declaration keyword:
string type (e.g., Operator '&' cannot be applied to types 'Config.Path' and 'number').
Master TypeScript with Deep Grasping Methodology!Learn More





