AOT - Angular 6 - Directive SomeComponent, Expected 0 arguments, but got 1. for self made Component

Well I have prepared here a minimal, complete, and verifiable example

I have noticed a missing parameter with @HostListner

sample of issue bellow :

@HostListener('window:resize', ['$event'])
onResize(): void {

}

simply remove '$event' and it works great.

Thanks to @trichetriche for your help.


I meet some similar error called ERROR in (1,1): : Directive SomeComponent, Expected 0 arguments, but got 1. as described inside this comment https://stackoverflow.com/a/50409526/9026103, but now it was happened with window:scroll

@HostListener('window:scroll', ['$event']) public onScroll(): void {
  ...
}

It not so obvious, because Directive defined inside the component (@HostListener) is like anonymous directive here in the message, and not so clear where I had to search for it. I solve this message with logic: if we provide $event to function called onScroll - we need to set here argument event like onScroll(event), so there are no arguments inside function handler of HostListener directive, and we receive this error. But it happened in my case in line 1, as described in error message, but @HostListener was declared below all the functions, and by hoisting and optimisations maybe, it appeared in line 1.

Solved code:

@HostListener('window:scroll', ['$event']) public onScroll(event /*provide $event to method here */): void {
  ...
}