To add a static property to a class in TypeScript, use the static
keyword followed by the property name and its value.
index.ts116 chars6 lines
In the example above, we add a static property called myStaticProperty
to the MyClass
class. The value of this property is "Hello World"
.
You can access this static property without creating an instance of the MyClass
class, like so:
index.ts64 chars2 lines
Note that static properties are shared among all instances of the class and can also be accessed within static methods.
gistlibby LogSnag