combineLatest deprecated in favor of static combineLatest

RxjsRxjs6

Rxjs Problem Overview


After running the rxjs migration tool using

> rxjs-5-to-6-migrate -p src/tsconfig.app.json

I'm now getting a linting error:

> combineLatest is deprecated: Deprecated in favor of static > combineLatest.

Here is my code before running the migration command:

this.store.combineLatest(
        this.store.select(lang.getCurrent),
        this.store.select(lang.getCurrentLocale)
    ).subscribe(([state, currentLang, locale]) => {
        this._language = session.language === currentLang ? '' : currentLang;
        this._locale = session.locale === locale ? '' : locale;
    });

My code after running the migration command: (currently presenting a linting error)

import {map, combineLatest} from 'rxjs/operators';
this.store.combineLatest(
        this.store.select(lang.getCurrent),
        this.store.select(lang.getCurrentLocale)
    ).subscribe(([state, currentLang, locale]) => {
        this._language = session.language === currentLang ? '' : currentLang;
        this._locale = session.locale === locale ? '' : locale;
    });

The question was asked in this stackoverflow questions, but it was not specific enough: Angular 6 ng lint duplicate errors and warnings, combineLatest is deprecated .

Rxjs Solutions


Solution 1 - Rxjs

In rxjs 6.5+

import { combineLatest } from 'rxjs';

combineLatest([a$, b$, c$]);

And for most applications it's helpful to map the array of observables to a new value as well:

combineLatest([a$, b$, c$]).pipe(
  map(([a$, b$, c$]) => ({
    a: a$, 
    b: b$, 
    c: c$
  }))
);

Also see: https://www.learnrxjs.io/learn-rxjs/operators/combination/combinelatest

Solution 2 - Rxjs

Deprecated!

Please refer to ofir fridman's answer for the correct syntaxs as of RxJs 6.5


I found an answer in this article titled: RxJS 6: What's new and what has changed? ( which comes from official docs):

The solution is to convert:

import { combineLatest } from 'rxjs/operators';

a$.pipe(combineLatest(b$, c$));

into:

import { combineLatest } from 'rxjs';

combineLatest([a$, b$, c$]);

Solution 3 - Rxjs

rxjs version 6.4.0

You should import map operator from RxJs operators for it to work

combineLatest(a$, b$, c$).pipe(map([a, b, c]) => treat(a, b, c))

Solution 4 - Rxjs

combineLatest with a list of subscribers:

combineLatest([aSubscriber, bSubscriber]).pipe(map((aRes, bRes)=>{
// your business logic
}));

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
QuestionSamerView Question on Stackoverflow
Solution 1 - Rxjsofir fridmanView Answer on Stackoverflow
Solution 2 - RxjsSamerView Answer on Stackoverflow
Solution 3 - RxjsAyman FtitiView Answer on Stackoverflow
Solution 4 - RxjsBrijesh LakkadView Answer on Stackoverflow