Enum vs Union Types
Enum Vs Union (π solution)
π¨βπΌ Great migration! You've converted the enum-based function to use union types.
Why use union types?
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 all cases. Never use enums.
// Most TypeScript developers today prefer:
type Status = 'pending' | 'active' | 'done'