Public property of exported class uses private type error in TypeScript

C: \ DEV \ OpenCMS \ Site \ Frontend \ Scripts \ LIES \ sinnovations> TSC sinnovations.listv iewbase.ts --module amd C: /dev/OpenCMS/Website/Frontend/Scripts/libs/sinnovations/sinnovations.listviewb ase. ts (11,5): error TS2025: columns of a public property of an exported class have or use the 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 I don’t know how else to get the effect above. Does anyone have a solution for exporting some interfaces by class, which is exported as export = class?

+7
typescript
source share
1 answer

I'm afraid you need to define the interface in another file. eg

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; 
+8
source share

All Articles