Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Public property of exported class is using private type error in TypeScript

Tags:

typescript

C:\dev\OpenCMS\Website\Frontend\Scripts\libs\sinnovations>tsc sinnovations.listv iewbase.ts --module amd C:/dev/OpenCMS/Website/Frontend/Scripts/libs/sinnovations/sinnovations.listviewb ase.ts(11,5): error TS2025: Public property 'columns' of exported class has or i s using private type '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;

I understand the error, but dont know how else to get the effect of above. Anyone have a solution to export some interfaces along a class that is exported as export = class?

like image 814
Poul K. Sørensen Avatar asked Sep 13 '13 20:09

Poul K. Sørensen


1 Answers

I am afraid you need to define the interface in another file. e.g.

a.ts:

interface Column {
    label: string;
}

and your code :

/// <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;
like image 101
basarat Avatar answered Nov 09 '22 09:11

basarat