【发布时间】:2014-01-15 10:45:39
【问题描述】:
我有简单的课程:
/// <reference path="..\typings\jquery\jquery.d.ts"/>
/// <reference path="..\typings\knockout\knockout.d.ts"/>
module Some.Namespace {
export class TestBase {
public field1: KnockoutObservable<string> = ko.observable("");
public onFieldChange: KnockoutComputed<string> = ko.computed(() => {
return this.field1();
}, this);
}
export class Test extends TestBase {
public field2: KnockoutObservable<string> = ko.observable("");
public onFieldChange() {
super.onFieldChange() + this.field2();
}
}
}
问题,打字稿不允许在被覆盖的方法中使用关键字 super。它说:
错误 1 类“Some.Namespace.Test”无法扩展类 'Some.Namespace.TestBase':类 'Some.Namespace.Test' 定义 实例成员函数“onFieldChange”,但扩展类 'Some.Namespace.TestBase' 将其定义为实例成员属性。
错误 2 只有基类的公共方法可以通过 “超级”关键字。
我怎样才能覆盖敲除计算方法并且不丢失基本方法?
【问题讨论】: