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;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With