Search code examples
javascriptangulartypescriptrxjsngrx

Angular 7 Type 'void' is not assignable to type 'ObservableInput<{}>'


I can not figure it out why i got this error

  getByURL(url: string): any {
    return this.apiService.get(url).pipe(map(data => data));
  }

  getByNextPage(): Observable<any> {
    const url = 'url';
    this.getByURL(url).pipe(
      expand(data => {
        console.log(data);
      })
    );
  }

I got this error at line that has expand(data => ... . I want to use expand() so i can recursive the call for the next api.

Type 'void' is not assignable to type 'ObservableInput<{}>'

Any hint would be really appreciate. Thanks


Solution

  • That is because you are using expand() operator badly. If you check documentation, the expand() operator has to return an Observable and you are not returning nothing.

    Even though you return "data" variable the error will still persist because that rule.

    Check this documentation