1

I try to use combineLatest:

import { combineLatest } from 'rxjs/Observable';

but I get the warning

combineLatest is deprecated: Deprecated in favor of static combineLatest. 

If I follow the solution provided in the RxJS v5.x to v6 Update Guide as it is stated here and I write

import { combineLatest } from 'rxjs';

then I get the tslint message:

This import is blacklisted, import a submodule instead

which seems a bit a snake biting its own tail...

If I use

import { combineLatest } from 'rxjs/internal/observable/combineLatest';

then it works without warning messages, but as far as I know, it's not recommended to import internal packages (correct me if I'm wrong).

Disabling tslint messages doesn't seem acceptable to me.

Example:

this.Subscription = combineLatest([a,b])
    .pipe(
      map( (...) )
    ).subscribe( (...) );

Which is the appropriate solution? Thanks.

xavier
  • 1,860
  • 4
  • 18
  • 46
  • show us your code (where you use the function ) and the rxjs version plz – Ghoul Ahmed May 28 '19 at 09:20
  • I think it could help you:https://stackoverflow.com/questions/50274275/angular-6-ng-lint-combinelatest-is-deprecated – Baruch Gans May 28 '19 at 09:22
  • The link I provided showed that the rxjs version is v6 but since it was too hidden I made it explicit. I added a very simple example. The other stackoverflow question doesn't solve my problem and the second solution produces precisely one of the tslint messages I mentioned. :-( – xavier May 28 '19 at 09:36
  • 1
    It sounds like you have conflicting lint rules. And you should never use internal import locations. – cartant May 28 '19 at 09:49
  • Only me? Isn't it happening to anyone using rxjs? – xavier May 28 '19 at 10:07
  • It looks like you have an older Angular project and you're trying to use it with newer RxJS. In Angular (or angular-cli aka ng) importing directly from `rxjs` was blacklisted. This is however not an issue in newer angular-cli and rxjs that supports import maps. – martin May 28 '19 at 10:33
  • I don't understand what you mean by and older Angular project: I have angular (7.2.15), tslint (5.16.0) and rxjs (6.5.2) updated to the latest versions, but the problem is still there. What should I still update? – xavier May 28 '19 at 14:55

3 Answers3

2

Try using import { combineLatest } from 'rxjs/index'; to avoid deprecated library or blacklisted lint.

See this: https://rxjs-dev.firebaseapp.com/api/index/function/combineLatest

Tito Leiva
  • 892
  • 1
  • 12
  • 29
1

Since this is the sanctioned by the official documentation way of importing combineLatest, tslint is just being silly here.

Edit your tslint.json and remove rxjs the "import-blacklist" entry.

mbojko
  • 13,503
  • 1
  • 16
  • 26
  • Importing all `rxjs` is deprecated because it's a huge package. I think it makes sense to import only the pieces you need... – xavier May 28 '19 at 09:42
  • `import { combineLatest } from 'rxjs'` isn't "importing all `rxjs`", it's exactly that: import only the pieces you need. – mbojko May 28 '19 at 09:47
  • Yes, you are right. What I meant is the accepted answer here: https://stackoverflow.com/questions/45697345/what-is-the-tslint-blacklist-and-why-does-angular-cli-default-rxjs-on-the-list-i . But this is quite contradictory with https://github.com/angular/devkit/issues/585 which, by the way, is already closed and it's not being changed. Why??? – xavier May 28 '19 at 10:06
0

I already found the solution, based on @martin's comment: my original project was created using Angular 6. When I upgraded Angular 6 to Angular 7 I didn't take into account that tslint.jsonhad been updated. This file was simplified and it included the line

"extends": "tslint:recommended"

(See here for more details). In the recommended tslint file, the package rxjs had been excluded from the blacklist.

So, I had an old version of the file tslint.json, I updated it and now I don't have this problem anymore.

xavier
  • 1,860
  • 4
  • 18
  • 46