I am chaining HTTP calls as per https://stackoverflow.com/a/34107312/470014 however I only want to execute the next call if the previous one returns null. So I have the following code:
public getTolerances() {
this.queryServer(12,34).pipe(
mergeMap(previous => {
if (previous) {
return of(previous);
} else {
return this.queryServer(0,34);
}
}),
mergeMap(previous => {
if (previous) {
return of(previous);
} else {
return this.queryServer(34,0);
}
}),
mergeMap(previous => {
if (previous) {
return of(previous);
} else {
return this.queryServer(0,0);
}
})
)
.subscribe((result) => {
console.log({result});
});
}
If the previous call returns a result I am using of
operator to return that as an observable. Is that necessary or is there a way I can drop them? It feels like I am unwrapping the promise and then wrapping it up again but if I just return previous
I get the following type error:
Argument of type '(result: unknown) => unknown' is not assignable to parameter of type '(value: unknown, index: number) => ObservableInput'. Type 'unknown' is not assignable to type 'ObservableInput'.ts(2345)