2 ms·
> One thing I find useful about enums is that they can be used as both types and values Makes sense. You can emulate that behavior by having an object literal
by disintegrator 2y ago
> One thing I find useful about enums is that they can be used as both types and values
Makes sense. You can emulate that behavior by having an object literal with const assertion AND a union type of the same name derived from the object literal.
- bubblyworld 2y agoRight, yeah - this is what I meant by const and typeof. It's definitely an option, but I'm nervous of relying on the semantics of const like that. But maybe I shouldn't be, it seems pretty idiomatic? (the typeof part is just so you don't repeat yourself, or did you have something else in mind?)