How to implement class constants in typescript?

Posted by Editorial Staff | Updated on

Want to implement class constants in typescript? TypeScript 2.0 has the readonly modifier:

It’s not exactly a constant because it allows assignment in the constructor, but that’s most likely not a big deal.

Alternative Solution

An alternative is to use the static keyword with readonly:


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