I recently tried out TypeScript's type inference feature, where we don't specify variable types like number, string, or boolean and let TypeScript figure it out during initialization or assignment.
However, I encountered some confusion in its behavior.
For example, in Case 1:
function func(arg1:number, arg2:string){
console.log(arg1 + arg2);
}
let v ;
v = func;
console.log(typeof v);
v = 8;
console.log(typeof v);
The code runs without errors, resulting in output: function and number
But in Case 2:
function func(arg1:number, arg2:string){
console.log(arg1 + arg2);
}
let v = func;
console.log(typeof v);
v = 8;
console.log(typeof v);
In this case, the TypeScript compiler throws an error: Type 'number' is not assignable to type '(arg1: number, arg2: string) => void'.
Can anyone help me figure out what I'm missing? ~