I am learning about call signatures concept in typescript. I saw an odd case by chance that: “function values are assigned to variables whose type is function type defined by using interface can omit some parameters at the end”.
the following code is the one i had run:
interface Caculator {
(num:number,msg:string):number
}
let getDoule : Caculator = function(num:number){ // missing the last param
return num*2;
}
let getOne:Caculator =()=>{ // missing all params
return 1
}
typescript compiler did not throw any error when i run the code above. This is the strange thing make me confused.
However, When calling the two functions in the code above, typescript compiler enforce me make calls that have 2 params (num and msg).
getDoule(1,'ahihi');
getOne(1900,'ahihi');
If I intentionally make calls like:
getDoule(1);
getOne();
The compiler immediately throws error.
Can you tell me why typescript accepts implementations of call signatures like the example above
1