Reputation: 891
I'm trying out some RxJS functions in Angular and copied some code from a tutorial (link). My project is configured in 'strict' mode. The app is simply logging the coordinates of a click in the console (I did a Stackblitz: link)
Both locally and on Stackblitz the app works BUT locally my IDE is displaying an error. On line 25 of AppComponent, within the subscribe
, onClick
is underlined and I get "No overload matches this call
". The problem seems to be related to the type definition MouseEvent
on line 12. If I change it to any
, the error disappears.
My assumptions are:
any
in my final call)My questions:
Upvotes: 0
Views: 123
Reputation: 10525
You can do it like this:
const eventListener = <K extends keyof DocumentEventMap>(type: K) =>
bindCallback<K, DocumentEventMap[K]>(document.addEventListener)(type);
Stackblitz: https://stackblitz.com/edit/angular-ivy-pzxguu?file=src/app/app.component.ts
You could also use fromEvent
from rxjs instead:
import { fromEvent } from 'rxjs';
...
fromEvent(document, 'click').subscribe(...);
Upvotes: 1