How do I get the return type of a class method in TypeScript

Viewed 5584

In newer TypeScript versions (I think 2.8 onwards?), I can easily obtain the return type of a function:

function f() { return "hi"; }
type MyType = ReturnType<typeof f>; //MyType is string

But I can't figure out to get the same info from a class method…

class MyClass {
  foo() { return "hi"; }
}

How do I get the return type of (new MyClass()).foo() ?

1 Answers
Related