Hello, I am currently facing an issue where I am trying to pass a function as an argument to another function and need to provide the type signature for that function. Initially, I attempted to solve this problem using the following code snippet:
const funct1 = (obj1: Object, funct2: <T, K>(a:T) => K, obj2: any) => {
///...
}
However, when I try to call it with a function like this:
const convertFromDate = (obj: Date) : number => {
return obj.valueOf() / 1000;
};
funct1(d1, convertFromDate, Date) // error: Type 'number' is not assignable to type 'K'.
//'number' is assignable to the constraint of type 'K',
// but 'K' could be instantiated with a different subtype of constraint 'unknown'.
The above error message was displayed. How can I properly define the type signature of a function that takes an argument of one type and returns another?