无法在TypeScript 2.7.2中实例化通用CustomEvent

时间:2018-03-01 04:44:43

标签: typescript typescript2.7

我在Visual Studio 2017(15.5.3)中使用TypeScript 2.7.2 SDK。

我正在尝试创建一个继承自CustomEvent<T>的类,其中T被指定为接口,因此我可以约束detail参数的类型(否则将为any)。

这是我的示例代码,它编译得很好:

export interface IFileSendingEventDetail {
    formData: FormData;
}

export class FileSendingEvent extends CustomEvent<IFileSendingEventDetail> {
    constructor(formData: FormData, bubbles: boolean = true) {
        super("file-sending", {
            detail: { formData },
            bubbles: bubbles
        });
    }
}

然而,当我尝试这段代码时:

const e = new FileSendingEvent(new FormData());

我在控制台中收到此错误:

  

TypeError:无法构造'CustomEvent':请使用'new'   运算符,此DOM对象构造函数不能作为函数调用。

我看不出我做错了什么 - 或者TypeScript中有错误吗?

0 个答案:

没有答案
相关问题