Skip to content

Comment on TypeScript Enums vs. Flow Enums

Comments

Many of these problems (some of which I didn't even know about because I avoid using enums) go away when you use union types instead. The implicit casting is one example, the display-name retrieval is another (assuming you use string literals for variants)

Some of them can worked around by structuring your code in certain ways (for example you could make sure every variant is covered by indexing into an object with `key in MyEnum`, or by returning from each switch case and requiring a particular return type)

But even setting those aside, I got burned so badly the last time I used Flow that I'm not sure anything could convince me to return to it

AboutSource Built by g1lg1l

Hackerly is an independent reader for Hacker News, built on the public HN API. Not affiliated with Y Combinator.