Home > database >  What does this Typescript interface syntax from the official docs mean?
What does this Typescript interface syntax from the official docs mean?

Time:07-08

I came across this code snippet on the Typescript namespaces page.

[snippet1]

export interface Selectors {
    select: {
      (selector: string): Selection;
      (element: EventTarget): Selection;
    };
}

I understand that the particular example is regarding an external library implemented in Javascript, and this declaration makes the library known to the Typescript compiler. Let's ignore the external library for the moment. If I were to write a class that implements the Selectors interface, what would that class look like?

Specifically, what does select in the code snippet signify - is it an overloaded method with 2 possible signatures? If I wrote it as shown below, would it mean the same? Then why write it as snippet1 above?

  • Related