Reputation: 5245
I have a function that retrieves values , inside it I use observable.
this.values$ = this.apiService.retrieveIndicatorHistory(this.indicatorName, this.currentPeriod)
.pipe(
tap(_res => console.log(`value: ${_res}`)),
map(
(_res: any) => {
this.indicatorService.changeLoadingIndicator(this.indicatorName, false);
return _res;
}
),
catchError((err: any) => {
this.indicatorService.changeLoadingIndicator(this.indicatorName, false);
return of(err);
})
In the same file I have a function that needs the values returned by the observable.
this.valuesCopy = _.cloneDeep(this.values$);
I get this error
error TS2322: Type 'Observable<any>' is not assignable to type 'any[]'.
I know that I should subscribe to the observable an retrieve values (inside retrieveIndicatorHistory
function)
I would to know if is there this.values$ | async
aquivalent in TS files?
Upvotes: 0
Views: 47
Reputation: 909
Please share complete file and package.json. This is clearly a TYPE issue. You can only assign value of similar type in Typescript.
But Answer to this question can be found here. Type 'Observable<any>' is not assignable to type '[]'
Upvotes: 1