问题
What is the difference between these two declarations of functions in TypeScript Interfaces?
interface IExample {
myFunction(str: string): void;
}
and
interface IExample {
myFunction: (str: string) => void;
}
回答1:
These declarations are completely equivalent.
The only relevant difference here is that the second form can't be used for function overloads:
// OK
interface Example {
myFunction(s: string): void;
myFunction(s: number): void;
}
// Not OK
interface Example {
myFunction: (s: string) => void;
myFunction: (s: number) => void;
}
来源:https://stackoverflow.com/questions/27509973/difference-of-typescript-function-declaration-in-interfaces