Could not use Observable.of in RxJs 6 and Angular 6

AngularRxjs6Angular Observable

Angular Problem Overview


 import { Observable, of } from "rxjs";

// And if I try to return like this
  return Observable.of(this.purposes);

I am getting an error stating, Property 'of' does not exist on type 'typeof Observable'

Angular Solutions


Solution 1 - Angular

Looks like cartant's comment is correct, the RxJS upgrade guide doesn't cover that method specifically but does say "Classes that operate on observables have been replaced by functions"

Which seems to mean all or most of those class methods like .of, .throw etc. have been replaced by a function

So instead of

import { Observable, of } from "rxjs";
Observable.of(this.purposes);

do

import { of } from "rxjs";
of(this.purposes);

Solution 2 - Angular

rxjs 6

import { PreloadingStrategy, Route } from '@angular/router';
import { Observable, of } from 'rxjs';

export class SelectivePreloadingStrategy implements PreloadingStrategy {
    preload(route: Route, load: Function): Observable<any> {
       return route.data && route.data.preload === false ? of(null) : load();
    }

 }

Solution 3 - Angular

To avoid black-list linting of the rxjs, import them like this:

import { Observable } from 'rxjs/Observable';
import { of } from 'rxjs/observable/of';

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionHarish KrishnanView Question on Stackoverflow
Solution 1 - Angulartim545View Answer on Stackoverflow
Solution 2 - AngularTiny KingView Answer on Stackoverflow
Solution 3 - AngularTito LeivaView Answer on Stackoverflow