Want to declare a delegate type in Typescript? In TypeScript, interfaces can have call signatures. In your example, you could declare it like this:
1 2 3 4 5 6 7 8 9 10 | interface Greeter { (message: string): void; } function sayHi(greeter: Greeter) { greeter('Hello!'); } // msg is inferred as string sayHi((msg) => console.log(msg)); |
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.