Type 'Observable<any>' is missing the following properties from type 'any[]': length, pop, push, join, and 18 more.

1 Answer 37253 Views
TreeView
Bob
Top achievements
Rank 2
Veteran
Iron
Bob asked on 04 Sep 2019, 12:16 PM

As soon as I add the following lines to my component (having first imported "of" from rxjs.

public children = (dataItem: any): any[] => of(dataItem.items);
public hasChildren = (dataItem: any): boolean => !!dataItem.items;

 

I get the folllowing error:

Type 'Observable<any>' is missing the following properties from type 'any[]': length, pop, push, join, and 18 more.

 

How do I implement the children and hasChildren properties?

 

 

 

 

 

1 Answer, 1 is accepted

Sort by
0
Dimiter Topalov
Telerik team
answered on 06 Sep 2019, 07:32 AM

Hello Bob,

Indeed, this is a mistake in our demo. Please refer to the correct code snippet:

https://www.telerik.com/kendo-angular-ui/components/treeview/data-binding/#toc-basics

public fetchChildren(node: any): Observable<any[]> {
          //Return the items collection of the parent node as children.
          return of(node.items);
      }

The RxJS "of" function returns an Observable as opposed to a JavaScript array, thus the return type of the "children" method is incorrect (any[]) whereas it has to be Observable<any[]> in this case:

https://stackblitz.com/edit/angular-8ltbyn?file=app/app.component.ts

I apologize for any inconvenience caused, and will fix the demo as soon as possible.

Regards,
Dimiter Topalov
Progress Telerik

Get quickly onboarded and successful with your Telerik and Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
TreeView
Asked by
Bob
Top achievements
Rank 2
Veteran
Iron
Answers by
Dimiter Topalov
Telerik team
Share this question
or