TypeScript enums have been a subject of debate since their inception. Many developers, including seasoned professionals, have voiced concerns about their usage, leading to a “DO NOT USE TypeScript Enum” movement. But are enums really that problematic? Let’s explore the recent developments and alternatives that have sparked this conversation.
The Erasable Syntax Revelation 🧐
With the release of TypeScript 5.8, a new configuration option called --erasableSyntaxOnly was introduced. This option only allows "erasable syntax" in TypeScript files. But what exactly is erasable syntax, and why does it matter?
Erasable vs. Non-Erasable Syntax
Erasable Syntax: This includes TypeScript-specific constructs that don’t generate additional runtime code, such as type, interface, and type annotations like let n: number.
Non-Erasable Syntax: These are constructs that generate additional JavaScript code at runtime, including enum, namespace (with runtime code), and class parameter properties.