Takeshi Tokugawa YD
Takeshi Tokugawa YD

Reputation: 923

TypeScript & JQuery: event in handler "has not" properties 'target' and 'currentTarget'

I got TS2339: Property 'target' does not exist on type 'Event'. in below code:

this.$Element.on('click', SELECTOR, (event: JQuery.Event) => {
    const $ClickedLink: JQuery<HTMLElement> = JQuery(event.target);
    //
}

event.currentTarget is also does not exist, as ... defined in JQuery types?

Of course, there are no errors in compiled JavaScript.

This code is not the Angular! I just combine JQuery and class-based OOP.

Upvotes: 2

Views: 1386

Answers (1)

Sean Vieira
Sean Vieira

Reputation: 159895

This is because the @types/jquery type for the event that is provided to a callback (as opposed to the $.Event function) is called TriggeredEvent, not Event:

this.$Element.on('click', SELECTOR, (event: JQuery.TriggeredEvent) => {
  const $ClickedLink: JQuery<HTMLElement> = JQuery(event.target);
  // ... snip ...
}

Upvotes: 13

Related Questions