I am getting the following error when I build the following typescript code.
Property 'runStaticMethod' is a static member of type 'DemoClass'
Typescript Code:
export class Main {
constructor(private demo: DemoClass) { }
public run() {
this.demo.runStaticMethod();
}
}
export class DemoClass {
public static runStaticMethod() {
console.log('run...');
}
}
new Main(DemoClass).run();
I am getting the following console error when I build the above typescript code. But the javascript code is running as expected.
Console Error:
Chitty:tsc NatarajanG$ tsc
src/index.ts:5:19 - error TS2576: Property 'runStaticMethod' is a static member of type 'DemoClass'
5 this.demo.runStaticMethod();
~~~~~~~~~~~~~~~
Chitty:tsc NatarajanG$
Because it's a static property and you should access it in the way how TS requires it: DemoClass.runStaticMethod(), despite javascript supports this.demo.runStaticMethod().
https://www.typescriptlang.org/docs/handbook/classes.html#static-properties
Each instance accesses this value through prepending the name of the class. Similarly to prepending
this. in front of instance accesses, here we prependGrid. in front of static accesses.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With