Trying to dispatch a contextMenu
event, I've noticed that in the MouseEvent
interface for TypeScript, the target
property is missing, even though it is documented in the contextMenu documentation.
Here's my TypeScript snippet:
const emulatedMouseEvent: MouseEvent = new MouseEvent('contextmenu', {
bubbles: true,
altKey: event.args[0],
ctrlKey: event.args[1],
shiftKey: event.args[2]
})
this.webview.dispatchEvent(emulatedMouseEvent)
Encountering a TypeScript error when attempting to add target: event.args[3]
:
Argument of type '{ bubbles: true; altKey: any; ctrlKey: any; shiftKey: any; target: any; }' is not assignable to parameter of type 'MouseEventInit'.
Object literal may only specify known properties, and 'target' does not exist in type 'MouseEventInit'.ts(2345)
Also, in lib.dom.d.ts:
Interface MouseEvent extends UIEvent {
(properties of MouseEvent interface...)
}
Although the MouseEvent documentation doesn't include a Target
property, I'm unsure of how to create a contextmenu
event with the target property, which is available on the event itself but not on the MouseEvent interface.
Edit: This is not a duplicate question, as the issue here relates to the absence of the Target property in the MouseEvent interface and the solutions provided do not address this specific scenario.