prefer-union-over-enum
enum and const enum declarations are forbidden. Use union types instead.
What it checks
Any enum Name { ... } or const enum Name { ... } declaration.
Why
TypeScript enums have several drawbacks that union types avoid entirely:
- Runtime code. A regular
enumcompiles to an IIFE that creates a reverse-mapping object — dead code for tree-shakers and extra bytes in every bundle. - Implicit numeric mapping.
enum Direction { Up, Down }silently assigns0and1. Passing an arbitrary number whereDirectionis expected is a type error only sometimes. - Import overhead. Enums require a value import in addition to a type import, complicating barrel files and type-only imports.
Union types are erased entirely at compile time and work naturally with as const objects for exhaustive maps.
Examples
✗ Incorrect
✓ Correct
Consumers import only what they need:
Exceptions
None. enum is never the right choice in this codebase.

