Ok, I have the following scenario:
type IHashFn = (arg: string) => number;
const hash: IHashFn = (arg) => {
return 42;
}
So far, so good. Now I want the function to be generic.
const hash: <T> (arg: T) => number = (arg) => {
return 42;
}
That works. But this doesn't:
type IHashFn<T> = (arg: T) => number;
const hash: <T> IHashFn<T> = (arg) => {
return 42;
}
I found no way to calm down the TS compiler. Using interfaces instead of type aliases doesn't work either.
Note: I dont't want hash to be an implementation for IHashFn<string> but generic as well.
Is there a way to declare generic function types or interfaces in TypeScript at all?