angular tutorials

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 🙂

References:

Leave a Reply

avatar
  Subscribe  
Notify of