I want to access the static member of a class through an object of this class.
I do it using obj.constructor. It works well except with the typescript linter which says
Property 'getName' does not exist on type 'Function'
class Foo {
public static getName(): string {
return 'foo';
}
}
const foo = new Foo();
const name: string = foo.constructor.getName();
I tried using : const name: string = (foo.constructor as Foo).getName();
but it gives me
Property 'getName' is a static member of type 'Foo'
EDIT :
It worked using : const name: string = (foo.constructor as typeof Foo).getName();
Is there any way it could work without manually casting the class?
INFO : I cannot call it directly using Foo.getName() in my specific case