I'm currently working on a project that involves using JQuery in Typescript. One challenge I'm facing is passing a mouse event from a JQuery element to a wrapper class. Here's an example of what I'm trying to achieve:
import * as $ from 'jquery'
export class Test {
ele: JQuery;
constructor() {
this.ele = $('<div>Hello World</div>');
this.ele.mousedown((evt) => { this.my_mousedown(evt); });
}
my_mousedown(evt: MouseEvent) {
console.log(evt);
}
}
The issue I'm encountering is that the type of evt being passed is incorrect:
Argument of type Event<HTMLElement | null> is not assignable to parameter of type 'MouseEvent'
I attempted to adjust my_mousedown to:
my_mousedown(Event<HTMLElement | null>
but received the error:
Event is not generic.
Lastly, when I converted evt back to its original Event type in the JQuery call, it lacked access to any mouse-specific properties like clientX
. Any suggestions on how to proceed?