Ask questionsAdd getBoundingClientRect to EventTarget type
Hi. I've found that I can't use getBoundingClientRect with MouseEvent in typescript.
onClick: (event: MouseEvent): void => {
const { left, top } = event.target.getBoundingClientRect();
const { left, top } = event.nativeEvent.target.getBoundingClientRect();
},
Typescript message I see in VS code is:
Property 'getBoundingClientRect' does not exist on type 'EventTarget'.ts(2339)
Answer
questions
droganov
This is what worked for me, but I guess for MouseEvent it should work out of the box
const node = event.target as HTMLElement;
Related questions