Angular 6: Property 'of' does not exist on type 'typeof Observable'

HD.. picture HD.. · Jun 15, 2018 · Viewed 17.9k times · Source

I am using Angular 6 using "rxjs": "^6.0.0",

ERROR : Property 'of' does not exist on type 'typeof Observable'.

import { Injectable } from '@angular/core';
import { TranslateLoader } from '@ngx-translate/core';
import { Observable, Subject, pipe, of } from 'rxjs';


@Injectable()
export class MiTranslateLoaderService implements TranslateLoader {

  getTranslation(lang: string): Observable<any> {
    return Observable.of({
      lbl_select: 'Select',
    });
  }
}

Answer

martin picture martin · Jun 15, 2018

Since RxJS 6 the correct and recommended way of using of() (RxJS 5 in Observable.of()) is this:

import { of } from 'rxjs';

I think this import { of } from 'rxjs/observable/of'; will work only while you have rxjs-compat package installed.