具有不同参数的继承和重写方法

时间:2013-01-15 14:04:15

标签: inheritance override typescript

我有一个继承HTMLElement的接口:

export interface IEElement extends HTMLElement {
    click: (event: IEEvent) => void;
    onmousedown: (event: IEEvent) => void;
    onmousemove: (event: IEEvent) => void;
    onmouseup: (event: IEEvent) => void;
}

在所有属性上获取错误:

Error Image

我想这是因为click() => void类型,但我的新架构不应该覆盖它吗?如何省略错误(我不想重命名我的属性 - 如果没有必要)?

1 个答案:

答案 0 :(得分:1)

将其设为可选(使用:?)

export interface IEElement extends HTMLElement {
    click: (event?: IEEvent) => void;
    onmousedown: (event: IEEvent) => void;
    onmousemove: (event: IEEvent) => void;
    onmouseup: (event: IEEvent) => void;
}