Home > Enterprise >  Type 'x[] | null' is not assignable to type 'x[]'
Type 'x[] | null' is not assignable to type 'x[]'

Time:09-30

I'm having an issue binding a value in angular. I have an observable returning an array as so:

entity$ = new Observable<Entity[]>(observer => {
if (this.entities[this.selectedEntityId] !== undefined) {
  observer.next([this.entities[this.selectedEntityId]]);
}
observer.complete();
})
.pipe(filter<Entity[]>(e => e !== undefined));

After that I'm trying to bind to it like this:

<dx-list>
   [selectedItems]="entityService.entity$ | async"
</dx-list>

Although I'm getting the error:

Type 'Entity[] | null' is not assignable to type 'any[]'.

I'm relatively new to angular so I'm stumped on this issue.

CodePudding user response:

a quick fix would be [selectedItems]="$any(entityService.entity$ | async)"

  • Related