我有一个界面:
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 .
1 回答
问题是
getChildren
onITreeViewItem
不是返回承诺的函数,它只是一个承诺 . 您可以将其声明为方法,通过添加()
返回Promise