I\'m trying to understand why we have different syntax for call signatures and for function types. Consider the following code:
interface MyInterface {
//
They are exactly the same.
why do we need two different yet so similar ways to write the same thing in typescript
The (x:number, y:number)=>number
signature is useful as a property
annotation :
interface MyInterface {
(x:number, y:string):string;
someProperty: (x:number, y:number)=>number;
}
Which is similar to your:
var myTwo : (x:number, y:number)=>number
Just a shorthand for a verbose :
var myTwo : {(x:number, y:number):number}
So you can see the simplicity of ()=>
.
One thing to note is that a function signature allows overloading:
var myTwo : {
(x:number, y:number):number;
(x:number):string;
}
Which is not supported for a property
annotation.