Observable.throw replacement in rxjs 5.5.2

In continuation to Mick's answer, in the rxjs version 6 _throw is replaced by throwError

 import {Observable, throwError} from 'rxjs'; 

RxJS Migration Guide


Yes _throw is correct(this will do exactly what JayChase wrote but is less code). You do the same with of:

import {of} from 'rxjs/observable/of';
import {_throw} from 'rxjs/observable/throw';

// ...
   // ...
   if (result) {
       return of(result as T);
   } else {
       return _throw('error');
   }
}

I'm still getting my head round 5.5 but it looks like now instead of importing throw use ErrorObservable.

// import { _throw } from 'rxjs/observable/throw';
import { ErrorObservable } from 'rxjs/observable/ErrorObservable';

ErrorObservable.create('error');

From this guide it looks like it has to be _throw to avoid a keyword clash (the rest of the video is good for getting started with 5.5)

Tags:

Angular

Rxjs