Can you provide an example of a TypeScript handler for a jQuery onclick event that accepts eventData?
A handler without eventData can be defined as follows:
let onClick(event: JQuery.Event): void
This handler can be registered like this:
$("#btn").click(onClick);
The following registration works fine in my test fiddle:
$("#btn").click("data3", onClick);
However, my IDE shows the following error:
Error TS2345 (TS) Argument of type '(event: Event) => any' is not assignable to parameter of type 'EventHandler | EventHandlerBase>'. Type '(event: Event) => any' is not assignable to type 'EventHandlerBase>'. Types of parameters 'event' and 't' are incompatible. Type 'Event' is not assignable to type 'Event'. Type '"data3"' is not assignable to type 'null'.
I understand that the type of the handler without eventData is:
JQuery.EventHandler<TElement>
and with eventData it is:
JQuery.EventHandler<TElement, TData>
How can I declare such an event handler using valid and type-safe TypeScript syntax?