TypeScript Master (50 Qs)•Part 1: Basic & Foundational TypeScript (Junior / Entry-Level)
Why does modern TypeScript favor String Union Types over Enums?
junior LevelTypeScript
In Simple Words: Numeric and standard Enums in TypeScript generate real JavaScript code during compilation (creating reverse-mapping object tables).
- Enums: Pollute the compiled bundle with runtime object overhead and can produce unsafe numeric assignments (
enum Status { Active, Inactive }). - String Literal Unions (
type Status = 'active' | 'inactive'): Fully erased at compile time, zero runtime code generated, fully serializable to JSON, and fully type-checked.