I am currently in the process of rewriting this code snippet:
Observable
.merge(this.searchQuery$, this.lazyQuery$)
.do(() => this.loadingPage())
.map(filter => this.buildURL("jaume", Config.security['appName'], filter))
.switchMap(url =>
this.service.getItemsFromStorage(url)
.map(response => this.buildPage(response))
.catch(() => Observable.of(pojo.Page.EMPTY))
)
.do(page => this.loadedPage(page))
.takeUntil(this.unsubscribe$)
.subscribe();
My goal is to utilize "pipable" syntax. So far, I have been able to rewrite it as follows:
this.searchQuery$.pipe(
merge(this.lazyQuery$),
tap(() => this.loadingPage()),
map(filter => this.buildURL("jaume", Config.security['appName'], filter))
)
.pipe(
switchMap(url => this.service.getItemsFromStorage(url)),
catchError(() => Observable.of(pojo.Page.EMPTY))
)
.pipe(
tap(page => this.loadedPage(page)) <<***>>
);
However, I am encountering a compiler error on <<***>>
:
Argument of type 'Response | Page' is not assignable to parameter of type 'Page'. Type 'Response' is missing the following properties from type 'Page': total, users
It appears that the catchError
is returning a {} | Page
type when it should be returning a single Page
type.
Any insights on how to resolve this issue?