Hacker News new | ask | show | jobs
by yCombLinks 1608 days ago
He is completely incorrect about the purpose of enums. It isn't to simplify changing all locations of an occurrence. It is for defining domain concepts. It is to communicate to other code users, here is every allowed permutation of this type.
2 comments

You can do that with sum types.

    type methods = 'a' | 'b'
    const value: methods = 'c' // error
The difference is enums are also nominal, while most types are structural.
I don't know if you are correct, but this is closest to how I think about it

Mechanically, a const dictionary, or a string union might achieve the same.

But semantically, an enum (sometimes) reads better.