To call a static property on an instance of a class in TypeScript, you would typically use the class name to access the static property, rather than the instance itself. Here's an example:
index.ts288 chars10 lines
In this example, we define a class, MyClass
, with both a static property, myStaticProp
, and an instance property, myInstanceProp
. We then create an instance of MyClass
, myInstance
, and access both properties using the instance (myInstance.myInstanceProp
) and class name (MyClass.myStaticProp
).
Note that attempting to access a static property with an instance variable will result in an error in TypeScript.
gistlibby LogSnag