Enum Compilation
What
Unlike most TypeScript features (like interfaces or type aliases), enums are not removed during compilation. Instead, they generate actual JavaScript code that exists at runtime.
How
A numeric enum like enum Class { Rogue } compiles into a JavaScript object that supports both forward and reverse mapping:
var Class;
(function (Class) {
Class[Class["Rogue"] = 0] = "Rogue";
})(Class || (Class = {}));
Why
Understanding how enums compile helps you realize that they add a small amount of overhead to your bundle. It also explains the “magic” behind bidirectional mapping for numeric enums and why string enums (which compile to simpler key-value pairs) cannot perform reverse lookups.
Summary
Enums are one of the few TypeScript features that have a “physical” presence in your compiled JavaScript files.