To add a public static property to a class in TypeScript, you can declare it inside the class declaration using the static keyword.
Example:
index.ts143 chars6 linesIn this example, we declared a public static property called myStaticProperty on the MyClass class. This property can be accessed without needing an instance of the class.
We can also modify the value of this property:
index.ts113 chars4 lines
This code will change the value of the myStaticProperty property to "Goodbye World!" and then log it to the console.
Static properties are useful for declaring values that are associated with a class as a whole, rather than with individual instances of the class.
gistlibby LogSnag