64
 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'

mruanova
  • 6,351
  • 6
  • 37
  • 55
Harish Krishnan
  • 1,693
  • 4
  • 17
  • 25
  • 22
    In v6 it'd be just `return of(this.purposes)`. – cartant May 08 '18 at 00:39
  • 3
    where is this documented? The typical line is "You pull in any operator you need from one spot, under 'rxjs/operators' " which is obviously different from creation, but it's not clear the static method has been replaced. This import knowledge being scattered across the galaxy like I'm looking for the Tox Uthat is just lost time. – Joe May 08 '18 at 18:06

3 Answers3

120

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);
tim545
  • 1,523
  • 1
  • 11
  • 12
4

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();
    }

 }
Tiny King
  • 121
  • 1
  • 4
0

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

import { Observable } from 'rxjs/Observable';
import { of } from 'rxjs/observable/of';
Tito Leiva
  • 892
  • 1
  • 12
  • 29