9

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 parameter's type, the error disappears. But any is the same as no type, isn't there a suitable type for functions as parameters?

1 Answer 1

12

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 {
    //...
Sign up to request clarification or add additional context in comments.

2 Comments

Ok. So it means the type is function with ev parameter of type Event that returns any?
Yes - although think of the return type as simply being very permissive. You can pass a function that returns void, or a string, or a number - whatever you like; allow any return type.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.