TypeScript: get type of instance method of class
You could use TypeScript's built in InstanceType
for that:
class MyClass
{
private delegate: InstanceType<typeof MyClass>['myMethod']; // gets the type (boolean) => number;
public myMethod( arg: boolean )
{
return 3.14;
}
}
you can use the following type:
type TypeOfClassMethod<T, M extends keyof T> = T[M] extends Function ? T[M] : never;
With that, you can write the following:
class MyClass
{
private delegate: TypeOfClassMethod<MyClass, 'myMethod'>; // gets the type (boolean) => number;
public myMethod( arg: boolean )
{
return 3.14;
}
}