The new ReturnType in TypeScript 2.8 is a really useful feature that lets you extract the return type of a particular function.
function foo(e:
TypeScript compiler does not see typeof foo as generic type. I'd say it's a bug in the compiler.
However, TypeScript has callable interfaces which can be generic without any problems, so if you introduce a callable interface compatible with the signature of your function, you can implement your own equivalent of ReturnType like this:
function foo(x: T): T {
return x;
}
interface Callable {
(...args: any[]): R;
}
type GenericReturnType = X extends Callable ? R : never;
type N = GenericReturnType; // number