type Func = (param?: number) => void
const func: Func = (param: number) => {}
I encountered the error:
Type '(param: number) => void' is not assignable to type 'Func'.
Types of parameters 'param' and 'param' are incompatible.
Type 'number | undefined' is not assignable to type 'number'.
Type 'undefined' is not assignable to type 'number'.(2322)
However, my understanding is that I'm assigning a variable to a Type, so I'm assigning 'number' to 'number | undefined', not the other way around.
Interestingly, the reverse assignment does not show any error:
type Func = (param: number) => void
const func: Func = (param?: number) => {}
But it appears that it should generate an error because it allows a function without any parameter to be assigned to a type that requires 'param' to be a number.
What am I missing? I would appreciate your help in clarifying this for me.