我在两个单独的文件中有两个对象:
import FooResults = require('fooresults');
class FooViewModel {
Results = ko.observable<FooResults[]>();
}
export = FooViewModel;
和:
class FooResults {
Id = ko.observable<number>();
Text = ko.observable<string>();
}
export = FooResults;
但是FooViewModel
抱怨私人访问,所以我切换到一个界面。
import FooResults = require('fooresults');
class FooViewModel {
Results: KnockoutObservable<IFooResults[]> = ko.observable<FooResults[]>();
}
export = FooViewModel;
和:
class FooResults implements IFooResults {
Id: KnockoutObservable<number> = ko.observable<number>();
Text: KnockoutObservable<string> = ko.observable<string>();
}
export = FooResults;
和:
declare interface IFooResults {
Id: KnockoutObservable<number>;
Text: KnockoutObservable<string>;
}
但是现在编译器在编译时抱怨FooViewModel
说它不能转换FooResults
为IFooResults
(尽管FooResults
编译得很好js
)。
怎么了?谢谢。
编辑:这是实际的错误...
/*
Compile Error.
See error list for details
D:/MyWebProject/Scripts/fooviewmodel.ts(18,4): error TS2012: Cannot convert 'KnockoutObservable<FooResults[]>' to 'KnockoutObservable<IFooResults[]>':
Call signatures of types 'KnockoutObservable<FooResults[]>' and 'KnockoutObservable<Symology.Insight.ViewModels.StreetWorks.Works.IFooResults[]>' are incompatible:
Type 'FooResults' is missing property 'Id' from type 'IFooResults'.
Call signature expects 0 or fewer parameters.
*/