Usually it's just
enum Method {
Get = "GET"
// ...
}
I usually always put doc comments on enums and their variants.Regarding why numeric ones are (only sometimes) more useful than string values: bit flags comes to mind, faster comparison of numbers than strings (not always tho... unless this is a misconception, but I don't believe so), you mentioned smaller bundle size already.
As for "auto" enums: the fact they're numbers now is an implementation detail. They could be unique Symbols in a future versions of typescript. You can do that manually now too, but I'm talking about the automatic (without assignment) syntax.
Regarding article: I... Half-agree. But I'd not completely disregard/avoid enums. At the very least, they can be useful to help model some behaviours/states in more readable, accessible, and coherent way (Other comments went into a more in-depth defence of enums, thought).
enum Method {
Get = "method/GET"
// ...
}
The string value can be very helpful for the reader - be it a human or log ingestorIf you just use the value within your code the runtime representation does not matter, you're completely right.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...
https://www.typescriptlang.org/docs/handbook/2/everyday-type...
What value do you think it offers here?
> I don't want to think about the question of runtime representation; I just want a set of arbitrary symbols that are different from one another.
I wouldn't know how such requirements translate into value for her. Personally, when I need a set of type-checked fixed values, I favour string literal unions because a readable runtime representation eventually comes in handy.
The only time I recall using symbols was in order to have a "newtype"-like construct, which is a different thing entirely.