DEV Community

Aaron B
Aaron B

Posted on

Typescript enum vs. "as const"

This is not a post where you learn anything. For those who want to learn, please see yourself to the exit. For those looking for unadulterated opinions from an old man yelling at clouds, then you've come to the right place.

This whole enum vs. "as const" debate is incredibly tedious and has done nothing except to further the social stock of pedants in the Typescript blogosphere. Because of this "debate" every few weeks I'm forced to opine about which one a like more or which one would fit better or which one is "bad" or which is convention, etc. The list of minor reasons goes on and on and talking about it really feels like discussing where we'd like certain grains on sand on the beach to be. A.K.A. I don't care.

Now it's not to say that people don't do this with the best of intentions. I get it, you want the code to be readable, refactorable, etc. And for this, you should be lauded. Too many times, I've seen code that is truly a nightmare because the people writing it didn't have time or didn't care enough to put some thought into it. But...I've got to say, spending days discussing how best to write a switch-statement will not move the ball as much as you think it will and most of this energy can be put towards bigger questions.

Conclusion

Typescript team, if you're listening, the truth is I don't know how to fix this. If the solution were easy, there wouldn't be > 300 issues on Github. But dear god, please do something and release me from these boring conversations.

Top comments (0)