The error says Supplied parameter do not match any signature of call target
.
When I replace Function
with any
as the second parameter's type, the error disappears. But any
is the same as no type, isn't there a suitable type for functions as parameters?
What are Callback Functions in TypeScript. A callback function is defined as a function passed into another function as an argument, which is then invoked inside the outer function to complete the desirable routine or action.
There are 2 kinds of callback functions: synchronous and asynchronous. The synchronous callbacks are executed at the same time as the higher-order function that uses the callback. Synchronous callbacks are blocking.
Types of Functions in TypeScript: There are two types of functions in TypeScript: Named Function. Anonymous Function.
Instead of Function
(or any
) you can use the following type for your callback
parameter:
(ev: Event)=> any
This matches the type expected by addEventListener
.
Here is the full function signature:
on(eventName: string, callback: (ev: Event)=> any, useCapture: boolean) : Dom.Element {
//...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With