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

I can not figure it out why i got this errorgetByURL(url: string): any {return this.apiService.get(url)

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

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

Share asked May 31, 2019 at 0:32 daniel8xdaniel8x 1,0804 gold badges20 silver badges38 bronze badges 2
  • Try adding a return statement to getByNextPage() b/c is not returning anything, – artemisian Commented May 31, 2019 at 0:53
  • @artemisian Thanks. stackoverflow./questions/56398014/…. I have another question here which related to this one. Not sure if you can take a quick look. I got stuck there. thanks – daniel8x Commented May 31, 2019 at 15:59
Add a ment  | 

3 Answers 3

Reset to default 2

You need check data type of data variable and return data in your method.

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

Your function does not return anything, hence the void. You need to return an observable.

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

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744930678a4601716.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信