Here's a breakdown:
interface A { f(): number }
Represents the syntax for defining a method, whereas this:
interface B { f: () => number }
Demonstrates how to declare a property with a function type.
Although there isn't much distinction in interfaces, it becomes clearer in a class scenario:
class MyNewClass {
myMethod1() {
return 0;
}
myMethod2 = () => {
return 0;
}
myMethod3 = function () {
return 0;
}
}
The compilation results in:
var MyNewClass = (function () {
function MyNewClass() {
this.myMethod2 = function () {
return 0;
};
this.myMethod3 = function () {
return 0;
};
}
MyNewClass.prototype.myMethod1 = function () {
return 0;
};
return MyNewClass;
}());
It's evident that only myMethod1
is a method linked to the prototype, while the other two are simply properties assigned within the constructor.