3

I am getting this error. I'm trying to use

import { catchError } from 'rxjs/operators' 

instead of

import 'rxjs/add/operator/catch'

But what to use instaed of rxjs/add/operator/do and rxjs/add/operator/toPromise?

1 Answer 1

2

The import statements depend on the RxJS version.

RxJS 5+

import 'rxjs/add/operator/catch';
import 'rxjs/add/operator/do';
import 'rxjs/add/operator/toPromise';

RxJS 6+

import { catchError, tap } from 'rxjs/operator';

The catch and do operators were replaced with catchError and tap respectively. Nothing has to be imported for toPromise since it isn't pipeable and invoked directly on an observable.

Also, if you're using toPromise you need to know that it is being deprecated in RxJS 7 and will be gone in RxJS 8.

Sign up to request clarification or add additional context in comments.

2 Comments

So, i dont need to use toPromise in my application?
@user13911625: As shown in the article, you could continue to convert observables to promises using lastValueFrom or firstValueFrom instead. However I'd tell you to refrain converting observables to promises unless there is an explicit need for it. Observables in general also provide more control over the stream of data.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.