Problem Statement
Show pros/cons of string enums vs as const objects for constants.
Explanation
String enums: easy to reference (`Status.Open`), type-safe, and self-documenting; emit helper code that may add bundle size; less tree-shakeable in some setups. `as const` objects: minimal runtime footprint, preserve literal types, easy to form unions via `typeof obj[keyof typeof obj]`; lack namespacing and reverse mapping; no automatic exhaustiveness helpers. Pick enums for library-style, namespaced constants; pick `as const` for lightweight, union-friendly constants in apps.
Code Solution
SolutionRead Only
enum Status { Open = 'OPEN', Closed = 'CLOSED' }
const STATUS = { Open: 'OPEN', Closed: 'CLOSED' } as const;
type StatusT = typeof STATUS[keyof typeof STATUS];