I have 2 functions that return Observables that I would like to execute one after another. function1 return
Observable<SomeDataObject>
and function2 return type
Observable<Any>
I want that the function that execute them return boolean based of the result of function1. I was managed to do so when running first function1, but now I would like to run function2 first, and I get the error:
"Argument of type '(res: <SomeDataObject>) => boolean' is not assignable to
parameter of type '(value:SomeDataObject, index: number) =>
ObservableInput<any>. Type 'boolean' is not assignable to type
ObservableInput<SomeDataObject>
See my code: This works:
return this.someService.function1().pipe(
switchMap(f1Result =>
{
this.someService.repositpry.f1ResultData = f1Result;
return this.someService.function2().pipe(
map(res =>
{
if (res) return true;
else return false;
}));
})
)
This fails:
return this.someService.function2.pipe(
switchMap(f2Result =>
{
this.someService.function1().pipe(
map(f1result =>
{
this.someService.repositpry.f1ResultData = f1Result;
})
);
if (f2Result) return true
else return false;
}));
Solution:
return this.someService.function2().pipe(
switchMap(f2Result =>
{
return this.someService.function1().pipe(
map((f1result) =>
{
this.someService.repositpry.f1ResultData = f1Result;
if (f2Result) return true
else return false;
})
);
}));