Reputation: 2884
I have an interface:
export interface ITreeViewItem {
getChildren: Promise<ITreeViewItem[]>;
...
and an implementation of it:
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;
}
...
For me it looks fine but I get an error:
Types of property 'getChildren' are incompatible.
Type '() => Promise' is not assignable to type 'Promise'.
Property 'then' is missing in type '() => Promise'.
What is wrong with my getChildren
implementation?
I am using TypeScript 2.5.3.
Upvotes: 1
Views: 1617
Reputation: 249476
The problem is getChildren
on ITreeViewItem
is not a function returning a promise, it's just a promise. You can declare it as a method, returning a Promise by adding ()
export interface ITreeViewItem {
getChildren() : Promise<ITreeViewItem[]>;
}
Upvotes: 2