What does object with parentheses in place of keys in TypeScript mean?

Viewed 270

What does object with parentheses in place of keys in TypeScript mean?

E.g. here

foo(success: { (): void; (): void; }) {}

I can not understand what does the success parameter represent.

1 Answers

{ (): void; (): void; } is just a callable type. The second (): void is a function overload. Though in this case it does nothing. In less magical way it could be written as:

interface Success {
  (): void
  (): void
}

function foo(success: Success) {}

This is mostly equivalent to foo(success: () => void) {}.

Related