I wrote a type for my click handle functions which return a value with the same type of it's parameter, the code is:
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
and then I defined my function like this:
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);
I was frustrated with this message'unknown' is not assignable to type 'number',how can I make it works well?
any idea is appreciated !