How To Resolve “Type ‘EventEmitter’ Is Not Generic” Error

I get this little error almost daily when working in Angular (Particularly in VS Code).

Type 'EventEmitter' is not generic.

The first time I got the issue, it drove me mad as I was copy and pasting code from another file where it was working just fine, yet in my new code file everything was blowing up.

As it turns out, NodeJS has it’s own version of “EventEmitter” that is not generic. When using VS Code or other IDE’s that have auto completion, they will sometimes pick this EventEmitter to import rather than the one from Angular. The way to check is to see what your import statement looks like. It should be coming from @angular/core :

import { EventEmitter } from '@angular/core';

In my (broken) case, it was :

import { EventEmitter } from 'events';

In actuality, there are a couple of EventEmitter objects. For example another half broken example would be :

import { EventEmitter } from 'stream';

So just check exactly where you are importing EventEmitter from to get around this pesky error!

Leave a Reply

Your email address will not be published. Required fields are marked *