Property 'of' does not exist on type 'typeof Observable

Angular

Angular Problem Overview


I was recently using observable on my authentication token like

Observable.of('token');

But it keeps giving me above mentioned error, though i have already imported this.

import {Observable} from 'rxjs/Observable';

Angular Solutions


Solution 1 - Angular

You need to import it:

for Angular >= 6.0.0

uses RxJS 6.0.0 Angular Changelog 6.0.0

import { of } from 'rxjs';

And its usage has been changed, you no longer call it off of Observable:

of('token');

RxJS v5.x to v6 Update Guide - HowTo: Convert to pipe syntax which uses of()

for Angular <= 5.x.xx

import 'rxjs/add/observable/of';

And it's used as you have in your question

Observable.of('token');

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
QuestionDevesh JadonView Question on Stackoverflow
Solution 1 - AngularGünter ZöchbauerView Answer on Stackoverflow