【问题标题】:Deprecated methods in rxjs v6rxjs v6 中不推荐使用的方法
【发布时间】:2019-10-13 18:42:15
【问题描述】:

我尝试使用combineLatest:

import { combineLatest } from 'rxjs/Observable';

但我收到警告

combineLatest is deprecated: Deprecated in favor of static combineLatest. 

如果我按照here 的说明关注the solution provided in the RxJS v5.x to v6 Update Guide 并写下

import { combineLatest } from 'rxjs';

然后我收到 tslint 消息:

This import is blacklisted, import a submodule instead

这有点像蛇咬自己的尾巴……

如果我使用

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

然后它可以在没有警告消息的情况下工作,但据我所知,不建议导入内部包(如果我错了,请纠正我)。

我似乎无法接受禁用 tslint 消息。

例子:

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

哪个是合适的解决方案?谢谢。

【问题讨论】:

  • 向我们展示你的代码(你使用函数的地方)和 rxjs 版本 plz
  • 我觉得可以帮到你:stackoverflow.com/questions/50274275/…
  • 我提供的链接显示 rxjs 版本是 v6,但由于它太隐藏了,所以我明确表示。我添加了一个非常简单的示例。另一个 stackoverflow 问题并没有解决我的问题,而第二个解决方案恰好产生了我提到的 tslint 消息之一。 :-(
  • 听起来你有冲突的 lint 规则。而且你永远不应该使用内部导入位置。
  • 只有我一个人?使用 rxjs 的人不会发生这种情况吗?

标签: angular rxjs tslint


【解决方案1】:

根据@martin 的评论,我已经找到了解决方案:我的原始项目是使用 Angular 6 创建的。当我将 Angular 6 升级到 Angular 7 时,我没有考虑到 tslint.json 已更新。这个文件被简化了,它包含了这一行

"extends": "tslint:recommended"

(See here 了解更多详情)。在推荐的 tslint 文件中,包 rxjs 已被排除在黑名单之外。

所以,我有一个旧版本的文件 tslint.json,我更新了它,现在我不再有这个问题了。

【讨论】:

    【解决方案2】:

    既然这是官方文档认可的导入combineLatest的方式,这里tslint就是傻了。

    编辑您的 tslint.json 并删除 rxjs 的 "import-blacklist" 条目。

    【讨论】:

    • 不推荐导入所有rxjs,因为它是一个巨大的包。我认为只导入你需要的部分是有意义的......
    • import { combineLatest } from 'rxjs' 不是“导入所有rxjs”,而是:只导入您需要的部分。
    • 是的,你是对的。我的意思是这里接受的答案:stackoverflow.com/questions/45697345/…。但这与github.com/angular/devkit/issues/585 完全矛盾,顺便说一句,它已经关闭并且没有被更改。为什么???
    【解决方案3】:

    尝试使用import { combineLatest } from 'rxjs/index'; 以避免已弃用的库或列入黑名单的 lint。

    看到这个:https://rxjs-dev.firebaseapp.com/api/index/function/combineLatest

    【讨论】:

      猜你喜欢
      • 2021-07-06
      • 1970-01-01
      • 1970-01-01
      • 2014-05-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-12-13
      相关资源
      最近更新 更多