How to compare Enums in TypeScript?

Posted by Jessica Taylor | Updated on

Want to compare Enums in TypeScript? There is another way: if you don’t want generated javascript code to be affected in any way, you can use type cast:

In general, this is caused by control-flow based type inference. With current typescript implementation, it’s turned off whenever function call is involved, so you can also do this:

The weird thing is, there is still no error if the id function is declared to return precisely the same type as its agument:


If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.

Related Questions & Answers