简体   繁体   English

角度打字稿 - 输入 EventEmitters

[英]angular typescript - typing EventEmitters

I want my EventEmitter to be typed to a set of classes我希望我的 EventEmitter 被输入到一组类中

export const EVENT_ACTIONS = {
    OPEN_EVENT: "OPEN_EVENT",
    OPEN_REGISTRATION: "OPEN_REGISTRATION"
}


export class OpenEventAction { type = EVENT_ACTIONS.OPEN_EVENT; constructor(public payload: SbEvent) { } }
export class OpenRegistrationAction { type = EVENT_ACTIONS.OPEN_REGISTRATION; constructor(public payload: SbEvent) { } }

export type EventActions
    = OpenEventAction
    | OpenRegistrationAction

In Component在组件中

@Output() eventOutput:EventEmitter<EventActions> = new EventEmitter();

I'm getting a Decorators are not valid here error and my IDE says Type EventEmitter ist not generic.我收到一个装饰器在这里无效的错误,我的 IDE 说类型 EventEmitter 不是通用的。

I don't really understand this error.我真的不明白这个错误。 Please help!请帮忙!

Cheers干杯

The problem for me was the incorrect import as mentioned by @JB Nizet in the comments.我的问题是@JB Nizet 在评论中提到的不正确的导入。 I was importing EventEmitter from events .我正在从events导入EventEmitter Instead the import needed to be import { EventEmitter } from '@angular/core' .相反,导入需要import { EventEmitter } from '@angular/core'

Then I was able to specify a type like so:然后我能够指定一个类型,如下所示:

@Output('search-term') searchTerm: EventEmitter<string> = new EventEmitter();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Angular 2结合了两个EventEmitter - Angular 2 combine two EventEmitters 级联操作(使用EventEmitters)用于下拉角度2 - Cascade operation (using EventEmitters) for dropdown angular 2 Angular 2 属性绑定:EventEmitters 如何工作? - Angular 2 property binding: how do EventEmitters work? 问题:Angular 9,使用 ControlContainer 和 EventEmitters 的带有孙组件的模板驱动表单? - Problem: Angular 9, template driven forms with grandchild components using ControlContainer and EventEmitters? 类在“键入”变量(VS接口)和“建模”(用于Typescript Angular 2项目)中的用法 - Usage of class in 'typing' the variable (vs interface) and 'modelling' (for Typescript Angular 2 project) 用于 SQL 提示的 Angular 上的 Codemirror 有效,但会出现 Typescript 输入错误 - Codemirror on Angular for SQL hints works but gives Typescript typing error SystemJS Typescript键入冲突 - SystemJS Typescript typing conflict 如何在不使用angular7中的事件发射器的情况下将数据从子组件传递到父数据? - How to pass the data from child components to parent data without using eventemitters in angular7? 使用forkJoin的打字稿打字错误 - Typescript typing error with forkJoin 当用户停止输入时,Angular2 @ TypeScript错误rxjs / Subject :: filtering - Angular2 @ TypeScript error rxjs/Subject:: filtering when user stops typing
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM