9

C:\dev\OpenCMS\Website\Frontend\Scripts\libs\sinnovations>tsc sinnovations.listviewbase.ts --module amd C:/dev/OpenCMS/Website/Frontend/Scripts/libs/sinnovations/sinnovations.listviewbase。 ts(11,5):错误 TS2025:导出类的公共属性“列”具有或正在使用私有类型“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 的类导出一些接口?

4

1 回答 1

9

恐怕您需要在另一个文件中定义接口。例如

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;
于 2013-09-24T09:06:44.740 回答