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'