Is there a type of callback functions in TypeScript?

enter image description here The error says Supplied parameter do not match any signature of call target . When I replace Function with any as the second type of parameter, the error disappears. But any matches the type of the type, is there a suitable type for the functions as parameters?

+5
source share
1 answer

Instead of Function (or any ), you can use the following type for the callback parameter:

 (ev: Event)=> any 

This corresponds to the expected type addEventListener .

Here is the full function signature:

 on(eventName: string, callback: (ev: Event)=> any, useCapture: boolean) : Dom.Element { //... 
+7
source

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


All Articles