Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

'Error' message: 'Property 'from' does not exist on type 'typeof Observable'

I am trying to learn reactive programming using RxJS. I was trying to create an observable from an array using Observable.from() method, but I am getting an error:

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

I scaffolded an Angular application using Angular CLI, so all the dependencies including RxJS package was imported correctly.

In app.component.ts I added below import statements:

import { Observable} from 'rxjs/Observable'
import 'rxjs/observable/from'

And my AppComponent class looks like this:

export class AppComponent {

  numbers: number[] = [1, 2, 3, 4, 5];

  callMyObservable() : void {  
    Observable.from(this.numbers);
  }
}  

But I am getting the above mentioned compile time error.

I am not sure how to make it work.

like image 903
Deepak Pathak Avatar asked Oct 29 '17 17:10

Deepak Pathak


People also ask

Is it possible to type'of'and'empty'in observable type?

Sorry, something went wrong. Property 'of' does not exist on type 'typeof Observable'. Property 'empty' does not exist on type 'typeof Observable'.

Is it possible to have an empty type of observable?

Thank's . Sorry, something went wrong. Property 'of' does not exist on type 'typeof Observable'. Property 'empty' does not exist on type 'typeof Observable'.

Does the classic 'property does not exist on type window in typescript'?

The code worked fine, but the classic 'Property does not exist on type Window in TypeScript' error flagged up on the build command and TypeScript complained about it endlessly. The Window type is defined in the lib.dom TypeScript module (as per the following documentation on TSDoc.


1 Answers

If you are using rxjs >=6.0.0 then you no longer use Observable.from. Instead from is a standalone function.

import { Observable, from} from 'rxjs';

//old way
var o = Observable.from([1, 2, 3, 4]);

//new way
var o = from([1, 2, 3, 4]);

I hope this is helpful since it took me a while to figure this out.

like image 81
abaga129 Avatar answered Sep 28 '22 18:09

abaga129