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;
}
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;
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.