How do I use catchError() and still return a typed Observable with rxJs 6.0?

后端 未结 1 639
逝去的感伤
逝去的感伤 2021-02-05 09:23

cdSo I\'m trying to migrate some of my Angular 5 code to 6, and I understand most of the changes required for rxjs to work using the .pipe() operator. It works as you would expe

1条回答
  •  没有蜡笔的小新
    2021-02-05 09:54

    You should be able to explicitly specify the type parameters to catchError to indicate that it won't return an observable that emits a value - that is, it will return Observable - and will always throw:

    getAlbums(): Observable {
        return this.httpClient.get(this.config.urls.url("albums"))
            .pipe(
                map(albumList => this.albumList = albumList),
                catchError(new ErrorInfo().parseObservableResponseError)
            );           
    }
    

    Doing so will see the type inferred from the pipe call to be Observable.

    0 讨论(0)
提交回复
热议问题