How do I get around this “Subject incorrectly extends Observable” error in TypeScript 2.4 and RxJS 5.x?

Solution RxJS 5.4.2 should now work perfectly with TypeScript 2.4.1. Simply upgrade to 5.4.2+ if possible. npm install –save rxjs@^5.4.2 Then try restarting your editor and/or recompile if you don’t see an immediate change. If not, the below solution should work. Why it’s happening TypeScript 2.4 has a strictness change, and Subject<T> isn’t lifting to … Read more

Best way to “flatten” an array inside an RxJS Observable

You can use concatAll() or mergeAll() without any parameter. dataFromBackend.pipe( tap(items => console.log(items)), mergeAll(), // or concatAll() ) This (including mergeMap) works only in RxJS 5+ because it treats Observables, arrays, array-like objects, Promises, etc. the same way. Eventually you could do also: mergeMap(val => from(val).pipe( tap(item => console.log(item)), map(item => item.name), )), toArray(), Jan … Read more

How to make HTTP request at an interval?

As @Adam and @Ploppy mentioned, the Observable.interval() is now deprecated not the preferred way of creating such an observable. The preferred way of doing this is via the IntervalObservable or TimerObservable. [currently in Typscript 2.5.2, rxjs 5.4.3, Angular 4.0.0] I wanted to add some usage to this answer to demonstrate what I found the best … Read more

Simple way to get the current value of a BehaviorSubject with rxjs5

As was pointed out by artur grzesiak in the comments, the BehaviorSubject interface was cleaned up, and the getter is now just myBehaviorSubject.value. I just wanted to add this as an answer because I almost didn’t read the comments to the original question, and would have missed the correct answer.

ObjectUnsubscribedError when trying to prevent subscribing twice

I would get the subscription and unsubscribe on it this way and not on the subject directly: ngOnInit() { this.pages$ = this.pagesService.getPagesListener(); this.subscription = this.pages$.subscribe((pages) => { // <——- this.pages = pages; console.log(pages); }); this.pagesService.getAll(); } ngOnDestroy() { this.subscription.unsubscribe(); // <——- }

Hot and Cold observables: are there ‘hot’ and ‘cold’ operators?

I am coming back a few months later to my original question and wanted to share the gained knowledge in the meanwhile. I will use the following code as an explanation support (jsfiddle): var ta_count = document.getElementById(‘ta_count’); var ta_result = document.getElementById(‘ta_result’); var threshold = 3; function emits ( who, who_ ) {return function ( x … Read more