Declaring const of generic type
There is a difference between a generic type that happens to be a function and a type that is a generic function.
What you defined there is a generic type that is a function. This means that we can assign this to consts that have the generic types specified:
type FunctionType<TValue> = (value: TValue) => void;
const bar: FunctionType<number> = (value) => { // value is number
}
To define a type that is a generic function we need to put the type parameter before the arguments list
type FunctionType = <TValue>(value: TValue) => void;
const bar: FunctionType = <TValue>(value) => { // generic function
}
I have been trying to solve the same problem, which occurs especially when I'm using higher order functions (or React components) returning other generic functions (or components). I've found following solution:
interface GenericFunctionType {
<T>(x: T): string
}
const genericFunction: GenericFunctionType = (x) => `doSomething with X ${x}`