EventEmitter Error: Expected 0 type arguments, but got 1 : Angular
I am getting the following error EventEmitter Error: Expected 0 type arguments, but got 1 in Angular.
Expected 0 type arguments, but got 1
I have followed the following link EventEmitter to use it in my header component with the @Output directive to emit custom events.
header.component.ts
import { Component} from '@angular/core'; import { EventEmitter } from 'events'; @Component({ selector:'app-header', templateUrl: './header.component.html' }) export class HeaderComponent { collapsed = true; menuItemSelected = new EventEmitter<string>(); onSelect(menuItem: string) { this.menuItemSelected.emit(); } }
But my IDE cribs the following error ” Expected 0 type arguments, but got 1 ” as shown below.
Expected 0 type arguments, but got 1.ts(2558) Peek Problem (Alt+F8) No quick fixes available
Also, the method EventEmitter.event() which emits the an event containing given value throws error ” Expected at least 1 arguments, but got 0 ” as shown below.
(method) internal.EventEmitter.emit(event: string | symbol, ...args: any[]): boolean Expected at least 1 arguments, but got 0.ts(2555) events.d.ts(44, 18): An argument for 'event' was not provided. Peek Problem (Alt+F8) No quick fixes available
Solution
The problem in the above typescript class (header.component.ts) is you would have used wrong import using emmet (suggestion tool)
import { EventEmitter } from 'events';
Instead of
import { EventEmitter } from '@angular/core';
That was the case with me. After, fixing the above import statement and the following onSelect() method those two errors gone away.
onSelect(menuItem: string) { console.log("Menu Selected :: " + menuItem); this.menuItemSelected.emit(menuItem); }
After, the above fixes, the header.component.ts angular component class code will look like below.
import { Component, EventEmitter, Output } from '@angular/core'; @Component({ selector:'app-header', templateUrl: './header.component.html' }) export class HeaderComponent { collapsed = true; @Output() menuItemSelected = new EventEmitter<string>(); onSelect(menuItem: string) { console.log("Menu Selected :: " + menuItem); this.menuItemSelected.emit(menuItem); } }
That’s all. Therefore, you need to check whether right imports and arguments at first instant. The error EventEmitter Error: Expected 0 type arguments, but got 1 disappeared.
Hope it helped 🙂
- Call ngOnInit() again from another function – Angular 9 ?
- ngOnChanges get new value and previous value – Angular
- Why do we need ngDoCheck lifecycle hook – Angular ?
- Global Angular CLI version is greater than your local version
- Upgrade Angular CLI to the latest version Angular 9 or 10 ?
- How to use new static option in ViewChild Angular 9 ?
- Project contents into angular components using ng-content
- Call ngOnInit() again from another function – Angular 9 ?
- ngAfterContentInit with Example – Angular
- How Angular Encapsulates Styles using ViewEncapsulation ?
- ngAfterViewInit with Example – Angular
- ngOnDestroy Example Angular
- Angular Component : In which lifecycle hook you can check value of DOM element ?
- @ContentChild TypeError: Cannot read property ‘nativeElement’ of undefined
- Access ng-content with @ContentChild – Angular Component
- How to select an element in a component template – Angular ?
- Difference between @ViewChild and @ContentChild – Angular Example
- Cannot find name ‘Output’ – Angular