【发布时间】:2019-03-04 18:34:53
【问题描述】:
我有一个界面:
export interface ITreeViewItem {
getChildren: Promise<ITreeViewItem[]>;
...
及其实现:
export class MyClass implements ITreeViewItem {
public async getChildren(): Promise<ITreeViewItem[]> {
let result = await this._fileSystemService.getContents(this.fullPath);
let items = result.map(x => {
let y: ITreeViewItem = null;
return y;
});
return items;
}
...
对我来说看起来不错,但我收到错误:
属性“getChildren”的类型不兼容。
类型 '() => Promise' 不可分配给类型 'Promise'。
类型“() => Promise”中缺少属性“then”。
我的getChildren 实现有什么问题?
我正在使用 TypeScript 2.5.3。
【问题讨论】:
-
在第一个代码块中,您将
getChildren作为属性;在第二个代码 sn-p 中,您将getChildren作为函数。