您應該能夠使用類似以下內容:
import * as ko from "knockout";
export class MyTypeScriptClass extends ko.templateEngine {
allowTemplateRewriting: boolean = false;
public renderTemplateSource(
templateSource: Object,
bindingContext: KnockoutBindingContext,
options: Object) {
return /* does some custom work */;
}
}
輸出ES5代碼非常不同,因爲它使用__extends
幫手:
var __extends = (this && this.__extends) || function (d, b) {
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
var ko = require("knockout");
var MyTypeScriptClass = (function (_super) {
__extends(MyTypeScriptClass, _super);
function MyTypeScriptClass() {
var _this = _super.apply(this, arguments) || this;
_this.allowTemplateRewriting = false;
return _this;
}
MyTypeScriptClass.prototype.renderTemplateSource = function (templateSource, bindingContext, options) {
return [];
};
return MyTypeScriptClass;
}(ko.templateEngine));
exports.MyTypeScriptClass = MyTypeScriptClass;
但行爲應該是一樣的。