Property interval does not exist in the type observable

Thejashwini Dev picture Thejashwini Dev · Mar 30, 2018 · Viewed 20.5k times · Source
ngAfterViewInit(){
     Observable.interval(3000).timeInterval().subscribe()=>{};    
}

Trying to invoke the Observable.interval() method it is throwing a compiler error "Property interval does not exist in the type observable".

Edit

import { Observable } from 'rxjs/Observable';

Note that the import statement is already included

Answer

David Walschots picture David Walschots · May 20, 2018

For RxJS 6+ the answer given by Tomasz Kula only applies when using the rxjs-compat package, which should only be used when in the process of converting an application from RxJS 5 to RxJS 6.

Within RxJS 6+, use:

import { interval } from 'rxjs';

interval(3000).subscribe(x => /* do something */)

Note that any Observable creation function that previously existed on the Observable type, should now be imported from 'rxjs'.