The first point here is just plain wrong, or maybe outdated — numbers are NOT accepted for numeric enum arguments. Give it a try on the TS playground right now.
The second argument makes no sense. If you use an enum as an arg type, you can't pass a string... Yeah, of course. Because that's the whole point of enums. You can change the string value of an enum member once, and all the literals change everywhere.
I have taken the code directly from the TS playground. And I'm afraid you misunderstood my second argument. It's not about the tooling, but about the resulting code.
Typescript enums aren’t deprecated. Can you share me an official statement from typescript on it? They are only discouraged for use by one side of the community, there are lovers for enums too.
Even on the official typescript website it lists problems, pitfalls using enums (instead of using const objects) typescriptlang.org/docs/handbook/e...
and it does not even touch frameworks, babel, and other build tools that all had (or still have) problems with typescript enums.
If you run your code everywhere besides your own dev machine you have to care about how it gets build, deployed and run by the user.
If you have 2 possible solutions, one of which is completely problem free and the over is fraught by countless pitfalls -> it may not be officially sunsetted, but is a bad choice to make in any case.
Even official maintainers/creators of typescript regret the creation of enums.
On the official docs it only lists pitfalls with const enums, which do not apply to enums generally. And even the const enum pitfalls, as it clearly says, only apply if you're emitting or consuming d.ts files.
and it does not even touch frameworks, babel, and other build tools that all had (or still have) problems with typescript enums.
What problems with frameworks or build tools are you referring to exactly? Personally in years of working with typescript and many different frameworks, and some pretty wild build pipelines, I don't think I recall ever having any issues related to enums specifically.
If you run your code everywhere besides your own dev machine you have to care about how it gets build, deployed and run by the user.
Sure but what does this have to do with ... enums? How would enums even have any effect on how your code gets deployed and ran by the user
If you have 2 possible solutions, one of which is completely problem free and the over is fraught by countless pitfalls
Again, what "countless pitfalls" are you talking about...
Even official maintainers/creators of typescript regret the creation of enums.
It may have problems, yes, but as far as I know it's not deprecated. And officially deprecated is the only kind of deprecated. You could say it's a bad practice to use it in your point of view, but you can't say it's deprecated. Deprecation is a way to say "this should be done differently and may be removed in future versions". I don't see that movement from Typescript.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Typescript enums are deprecated and should not be used anymore.
Const objects are the way to go in typescript/javascript.
If you need 1 or more value mappings you use:
similar article
dev.to/ivanzm123/dont-use-enums-in...
The first point here is just plain wrong, or maybe outdated — numbers are NOT accepted for numeric enum arguments. Give it a try on the TS playground right now.
The second argument makes no sense. If you use an enum as an arg type, you can't pass a string... Yeah, of course. Because that's the whole point of enums. You can change the string value of an enum member once, and all the literals change everywhere.
I have taken the code directly from the TS playground. And I'm afraid you misunderstood my second argument. It's not about the tooling, but about the resulting code.
Hey, my comment wasn't about your article, but the one linked in the comment I replied to.
Typescript enums aren’t deprecated. Can you share me an official statement from typescript on it? They are only discouraged for use by one side of the community, there are lovers for enums too.
Even on the official typescript website it lists problems, pitfalls using enums (instead of using const objects)
typescriptlang.org/docs/handbook/e...
and it does not even touch frameworks, babel, and other build tools that all had (or still have) problems with typescript enums.
If you run your code everywhere besides your own dev machine you have to care about how it gets build, deployed and run by the user.
If you have 2 possible solutions, one of which is completely problem free and the over is fraught by countless pitfalls -> it may not be officially sunsetted, but is a bad choice to make in any case.
Even official maintainers/creators of typescript regret the creation of enums.
Hence my TLDR summary: enums are deprecated
On the official docs it only lists pitfalls with const enums, which do not apply to enums generally. And even the const enum pitfalls, as it clearly says, only apply if you're emitting or consuming d.ts files.
What problems with frameworks or build tools are you referring to exactly? Personally in years of working with typescript and many different frameworks, and some pretty wild build pipelines, I don't think I recall ever having any issues related to enums specifically.
Sure but what does this have to do with ... enums? How would enums even have any effect on how your code gets deployed and ran by the user
Again, what "countless pitfalls" are you talking about...
Citation needed
Well you're wrong though. They're not deprecated.
It may have problems, yes, but as far as I know it's not deprecated. And officially deprecated is the only kind of deprecated. You could say it's a bad practice to use it in your point of view, but you can't say it's deprecated. Deprecation is a way to say "this should be done differently and may be removed in future versions". I don't see that movement from Typescript.