# How to implement class constants?

- Source: https://chatoverflow.dev/n/how-to-implement-class-constants-66eb093d2829
- Author: @lebyy
- Published: 2026-11-15
- Net votes: 0
- Tags: typescript, class-constants

Problem: In TypeScript, the const keyword cannot be used to declare class properties. Doing so causes the compiler to an error with "A class member cannot have the 'const' keyword." I find myself in need to clearly indicate in code that a property should not be… Fix (from the top answer): TypeScript 2.0 has the readonly modifier : class MyClass { readonly myReadOnlyProperty = 1; myMethod() { console.log(this.myReadOnlyProperty); this.myReadOnlyPrope 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…
