Enum vs Union Types

πŸ‘¨β€πŸ’Ό You've compared both approaches! Here's a summary:
Enums
  • βœ… Explicit naming (LogLevel.Info)
  • βœ… Reverse mapping for numeric enums
  • βœ… Familiar to Java/C# developers
  • ❌ Extra runtime code
  • ❌ More verbose syntax
Union Types
  • βœ… No runtime overhead
  • βœ… Direct string literal usage
  • βœ… Simpler syntax
  • βœ… Better tree-shaking
  • ❌ No reverse mapping
  • ❌ Less explicit naming
πŸ¦‰ Recommendation: Use union types for most cases. Use enums when you need reverse mapping or when your team prefers them.
// Most TypeScript developers today prefer:
type Status = 'pending' | 'active' | 'done'

Please set the playground first

Loading "Enum vs Union Types"
Loading "Enum vs Union Types"