Difference in TypeScript function declaration in interfaces

What is the difference between these two function declarations in TypeScript Interfaces?

interface IExample {
  myFunction(str: string): void;
}

and

interface IExample {
  myFunction: (str: string) => void;
}
+1
source share
1 answer

These ads are fully equivalent.

The only difference is that the second form cannot be used to overload functions:

// OK
interface Example {
    myFunction(s: string): void;
    myFunction(s: number): void;
}

// Not OK
interface Example {
    myFunction: (s: string) => void;
    myFunction: (s: number) => void;
}
+1
source

Source: https://habr.com/ru/post/1677067/


All Articles