After developing a type for my click handle functions that should return a value with the same type as its parameter, I encountered the following code:
type OnClickHandle = <T extends unknown = undefined>(p: T extends infer U ? U : T) =>
T extends infer U ?
U extends number ? number :
U extends string ? string :
U extends undefined ? void :
void :
void
Subsequently, I attempted to define my function as such:
const handleReceive: OnClickHandle = (p: number) => p;
//ERROR: Type '(p: number) => number' is not assignable to type 'OnClickHandle'.
Types of parameters 'p' and 'p' are incompatible.
Type 'T extends infer U ? U : T' is not assignable to type 'number'.
Type 'unknown' is not assignable to type 'number'.
Type 'unknown' is not assignable to type 'number'.ts(2322)
handleReceive(0);
Encountering the error message 'unknown' is not assignable to type 'number' left me feeling frustrated. Any suggestions on how to resolve this issue are greatly appreciated!