C:\ dev的\ OpenCms的\网站\前端\脚本\库\ sinnovations> TSC sinnovations.listv iewbase.ts --module amd C:/dev/OpenCMS/Website/Frontend/Scripts/libs/sinnovations/sinnovations.listviewb ase.ts(11,5):错误TS2025:导出的公共属性“列” class有或者我使用私有类型'KnockoutObservableArray'。
/// <reference path="../../typings/knockout/knockout.d.ts" />
import ko = require('knockout');
interface Column {
label: string;
}
var _templateBase = '/Frontend/Templates/ListView/';
class ListViewBase<T> {
columns: KnockoutObservableArray<Column> = ko.observableArray([]);
rows: KnockoutObservableArray<T> = ko.observableArray([]);
constructor(public templateHeaderRow = _templateBase+'DefaultTableHeaderTemplate', public templateBodyRow = _templateBase + 'DefaultTableRowTemplate') {
}
addColumn(column: Column) {
this.columns.push(column);
}
addRow(row: T) {
this.rows.push(row);
}
static configure(templateBase) {
_templateBase = templateBase;
}
}
export = ListViewBase;
我理解错误,但不知道如何获得上述效果。任何人都有一个解决方案,可以导出一些导出为export = class的类的接口?
答案 0 :(得分:8)
我担心你需要在另一个文件中定义接口。例如
a.ts:
interface Column {
label: string;
}
和你的代码:
/// <reference path="../../typings/knockout/knockout.d.ts" />
/// <reference path="./a.ts" />
import ko = require('knockout');
var _templateBase = '/Frontend/Templates/ListView/';
class ListViewBase<T> {
columns: KnockoutObservableArray<Column> = ko.observableArray([]);
rows: KnockoutObservableArray<T> = ko.observableArray([]);
constructor(public templateHeaderRow = _templateBase+'DefaultTableHeaderTemplate', public templateBodyRow = _templateBase + 'DefaultTableRowTemplate') {
}
addColumn(column: Column) {
this.columns.push(column);
}
addRow(row: T) {
this.rows.push(row);
}
static configure(templateBase) {
_templateBase = templateBase;
}
}
export = ListViewBase;