I'm pretty sure TypeScript has a way of doing this but I haven't figured it out yet.
Is there a way to extract a generic type from the typeof a generic function?
Consider this simple generic function:
function echo<T> (input: T) {
return input;
}
I want to extract the generic type of this function. I tried:
type IEchoFn = typeof echo;
But it's unusable:
const echo2: IEchoFn = (input: string) => input;
^^^^^
// Type '(input: string) => string' is not
// assignable to type '<T>(input: T) => T'.
I thought I'd write it as
type IEchoFn<T> = (typeof echo)<T>;
But this is invalid syntax.
How can I extract a generic type from the typeof a generic function (or its return value)?