Property 'clientX' does not exist on type 'Event'. Angular2 Directive

22.7k views Asked by At

I'm trying to listen to the X position of my mouse in an Angular2 Directive like this:

@HostListener('mousemove', ['$event'])
onMousemove(event: Event): void  { 
  console.log(event.clientX)
}

but I get the error

Property 'clientX' does not exist on type 'Event'.

This is odd because this listener

@HostListener('mousemove', ['$event'])
onMousemove(event: Event): void  { 
  console.log(event)
}

logs out an event object

enter image description here

Why can I not access event.clientX?

1

There are 1 answers

2
Günter Zöchbauer On BEST ANSWER

Change the parameter type

onMousemove(event: MouseEvent): void  { 
  console.log(event.clientX)
}