3 ms·
Why do you find them self documenting? Usually it's just enum Method { Get = "GET" // ... } I usually always put doc comments on enums an
by spoiler 5y ago
Why do you find them self documenting?
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).
- KuhlMensch 5y agoenum Method { Get = "method/GET" // ... } The string value can be very helpful for the reader - be it a human or log ingestor