Hacker News new | ask | show | jobs
by homebrewer 479 days ago
const enums are almost never mentioned by these articles for some reason. They give you the best of both worlds: they're fully erasable, and have good LSP support (do no need to search for strings and bump into false matches — or even worse, for numbers).
2 comments

Lack of LSP support looks really bad in the article proposed solution :/.

But const enum seems to have several pitfalls. https://www.typescriptlang.org/docs/handbook/enums.html

> const enums are almost never mentioned by these articles for some reason.

I think it's because a lot of tooling (excepting TSC) doesn't support cross-file const enums. But I agree - it's one of the reasons I started using TypeScript way back in 2013. I wouldn't be able to write comprehensible performance sensitive code without it.