Consider the following function.
public static convert<T, U>(t: T, conversion: ((toutput: T) => U) = ((t) => t)) {
return conversion(t);
}
Typescript currently complains about the toutput parameter return from the conversion function, which is the defaulted parameter:
Type 'T' is not assignable to type 'U'. 'U' could be instantiated with an arbitrary type which could be unrelated to 'T'.
I'm attempting to get the IDE to recognize that, given the default parameter, T is the same as U.
My use cases are the following:
convert(1) // returns 1
convert(1, x => ({x})) // returns an object with { x : 1 }
Is there any way that anybody knows of to silence the compiler and be able to create this function above properly?