8

What is the correct expression and import for Observable.of([]);.

import { of } from 'rxjs'; does not work for me.

Jonathan Hall
  • 75,165
  • 16
  • 143
  • 189
Rose Nettoyeur
  • 885
  • 1
  • 16
  • 29

2 Answers2

19

Since RxJS 6 you should import all "creation" observables directly from 'rxjs' (assuming you have path maps set when bundling your app).

More detailed explanation: https://github.com/ReactiveX/rxjs/blob/master/MIGRATION.md#import-paths

import { of } from 'rxjs';

of(1).subscribe(console.log);

See demo: https://stackblitz.com/edit/typescript-e3lxkb?file=index.ts

martin
  • 93,354
  • 25
  • 191
  • 226
  • 1
    FYI... Link is broke. Also, came here hunting for comparison between the operator and the creator of `of` – Adam Cox Jul 10 '20 at 20:40
-1

No need to use Observable.of(T) Instead you can use the below syntax in the rxjs 6.3.3

return new Observable<AppUser>();
sushil suthar
  • 639
  • 9
  • 12