Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

Just moved from rxjs 5/angular 5 to rxjs 6/ angular 6, went through this migration-guide. Can't seem to figure out what it should be now, any help appreciated.

import { Observable, of } from 'rxjs'; [ts] 'of' is declared but its value is never read.  // trivial example of what im trying to replace   isLoggedIn(): Observable<boolean> {     return Observable.of(true);   } 
like image 435
alphapilgrim Avatar asked Jun 07 '18 23:06

alphapilgrim


People also ask

Does not exist on type Typeof?

The "Property does not exist on type Object" error occurs when we try to access a property that is not contained in the object's type. To solve the error, type the object properties explicitly or use a type with variable key names.

What is of in RxJS?

RxJS' of() is a creational operator that allows you to create an RxJS Observable from a sequence of values. According to the official docs: of() converts the arguments to an observable sequence. For example: import { of } from 'rxjs'; of(1, 2, 3, 4) .


2 Answers

You can now just import of from rxjs. So....

import { Observable, of } from 'rxjs';  // trivial example of what im trying to replace   isLoggedIn(): Observable<boolean> {     return of(true);   } 
like image 183
MichaelSolati Avatar answered Oct 05 '22 12:10

MichaelSolati


If you are using Angular 6 /7 or 9

import { of } from 'rxjs'; 

And then instead of calling

Observable.of(res); 

just use

of(res); 
like image 28
Mohammad Aljunde Avatar answered Oct 05 '22 12:10

Mohammad Aljunde