-
Notifications
You must be signed in to change notification settings - Fork 9
Description
I've read your rationale about not supporting auto initialization.
And yes, Typescript got this wrong in so many ways.
The main concern that has been raised is that introducing new auto-initialized enum members in the middle of an existing enum has the potential to be a versioning issue in packages
true.
but then you state that you might support this:
enum Numbers of Number { zero, one, two, three }
Numbers.zero; // 0but this is just a verbose way to opt into the problem. 🫤
why wouldn't you consider the obvious, idiomatic thing?
enum Colors { red, green, blue }
Colors.red; // "red"the fact is, this is what most developers want.
not numbers, which aren't easy to interpret over the wire, and not symbols, which don't even survive JSON.stringify, but plain old, idiomatic strings.
easy to read, easy to debug, adding no significant overhead compared with numbers (except in very marginal, hyper optimized transport protocol scenarios) and none of the problems you highlighted with numbers, typescript's default behavior.
most userland code right now is literally just const COLOR_RED = 'red', or sometimes as const with derived types in Typescript.
Typescript's enum literal is probably the most unpopular of all options. 😌
my point is, strings have always been the de facto standard symbols in JavaScript. (even after the addition of literal symbols, which don't survive JSON transport.)
this is what native enums are up against, right? a series of bad options.
forcing initialization of members with strings identical to those members names only adds useless verbosity and another source of bugs or confusing code.
I am only half serious here, but if auto initializing with strings was the only option for enums, that would probably be perfectly fine for 95% of use cases.
support the most common use case, by defaulting to the most common, most idiomatic pattern native to JavaScript, please. 🙏
I know you likely won't, because it would be a breaking change in Typescript... well, then at least, we can be honest and say that Typescript is now governing the design of JavaScript. 😌