Answer the question
In order to leave comments, you need to log in
Is it possible to set a default value for a function that depends on two generic types?
Working code example:
const displayFunctionCode = <T, P>(callback: (props: T) => P) => {
console.log(callback);
}
displayFunctionCode<number, number>((n) => n);
(prop: T) => props as P;
Answer the question
In order to leave comments, you need to log in
There is such a construction: - by double casting you can cast anything into anything.
Only here you don’t need to do this, this one kills the whole point of using TypeScript.
Instead, you need to write conditions in the "default function" so that it works as it is described, and not the hell understand how. foo as unknown as Type
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question