How to import ErrorObservable or _throw in rxjs6? throw in rxjs

Martin Nuc picture Martin Nuc · Apr 13, 2018 · Viewed 7.6k times · Source

I am migrating to rxjs 6.0.0-ucandoit-rc.6. In version 5.5.2 I was using ErrorObservable to create errorous observable.

I was using the way recommended here: https://github.com/ReactiveX/rxjs/blob/master/doc/pipeable-operators.md

Because throw is a key word you could use _throw after import { _throw } from 'rxjs/observable/throw'.

However this is not recommended way to import in rxjs6 anymore.

What is correct way how to import _throw or ErrorObservable?

Answer

cartant picture cartant · Apr 14, 2018

In RxJS version 6, _throw has been renamed to throwError and should be imported like this:

import { throwError } from "rxjs";

Alternatively, you can install rxjs-compat alongside rxjs version 6 to continue to use the old, version 5 exports:

import { _throw } from "rxjs/observable/throw";

For more information, see the migration guide.