To call a protected static property on an instance of a class in TypeScript, you can use the following syntax:
index.ts275 chars13 lines
In this example, we define a MyClass
with a protected static
myProperty
property. We then create a MyChildClass
which extends MyClass
.
Inside MyChildClass
, we create a public method logMyProperty
that logs the myProperty
value using the MyChildClass.myProperty
syntax, since MyChildClass
extends MyClass
.
We then create an instance of MyChildClass
and call the logMyProperty
method on it, which outputs the value of the myProperty
property. Note that we do not need to use the new
keyword when accessing the static property; instead, we use the class name followed by the property name (MyChildClass.myProperty
).
gistlibby LogSnag