A numeric enum in TypeScript is a strongly typed data structure that defines a collection of named constants mapped to discrete, auto-incrementing numeric values. By default, the underlying numeric values are zero-indexed, meaning the first member is assignedDocumentation Index
Fetch the complete documentation index at: https://docs.syntblaze.com/llms.txt
Use this file to discover all available pages before exploring further.
0, and each subsequent member increments by 1.
Custom Initialization
You can override the default zero-indexing by explicitly assigning a numeric value to one or more members. Uninitialized members that follow an initialized member will automatically increment by1 from the preceding value.
Constant and Computed Members
Numeric enum members fall into two categories: constant and computed.- Constant members are evaluated at compile time. They include literal numbers, references to previously defined constant enum members, and simple mathematical or bitwise expressions.
- Computed members are evaluated at runtime, typically via a function call.
Reverse Mapping
Unlike string enums, numeric enums support reverse mapping. The TypeScript compiler generates an object that maps the member name to its numeric value, and the numeric value back to its member name.Compilation Output
To facilitate reverse mapping, TypeScript compiles numeric enums into an Immediately Invoked Function Expression (IIFE) in JavaScript. The assignmentResponseCode["Success"] = 200 returns 200, which is then used as the key for the reverse assignment ResponseCode[200] = "Success".
Master TypeScript with Deep Grasping Methodology!Learn More





