本文介绍了“类型'EventEmitter'不是通用的"角度错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我当前正在学习一个教程,并且该教程正在使用EventEmitter.代码是这样的

I'm currently following a tutorial and the tutorial is making use of EventEmitter. The code goes like this

@Output() ratingClicked: EventEmitter<string> =
        new EventEmitter<string>();

但是Visual Studio代码却给了我这些错误:

But it visual studio code gives me these errors:

  1. 类型'EventEmitter'不是通用的.
  2. 期望0个类型参数,但得到1个.

即使在角度网站中,该代码也是正确的.

Even in the angular website it looks like that code is correct.

我当前正在使用Angular CLI:1.7.4;节点:8.11.1;打字稿:2.8.1

I'm currently using Angular CLI: 1.7.4; Node: 8.11.1; Typescript: 2.8.1

推荐答案

您可能正在使用node/index.d.ts中的node本机EventEmitter,即

You are probably using the node native EventEmitter from node/index.d.ts i.e.

import { EventEmitter } from 'events';

修复

将导入更改为角度导入:

Fix

Change the import to the one from angular:

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

这篇关于“类型'EventEmitter'不是通用的"角度错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-25 03:18