首页 > 解决方案 > Angular v6、rxjs v6 错误 TS2339:“OperatorFunction”类型上不存在属性“管道”

问题描述

我已经使用 rxjs-lint 包和以下命令更新了使用 Angular 6/rxJS6的新管道方法在Angular 5.5/rxJS5.5 上运行良好的代码

npm i -g rxjs-tslint
rxjs-5-to-6-migrate -p tsconfig.json

Imports 等已按预期进行了修改,但现在与 Angular 的 v5/RxJS 的 5.5 正常工作的代码出现以下错误:

 error TS2339: Property 'pipe' does not exist on type 'OperatorFunction<{}, {} | RouterEvent | RouteConfigLoadStart | RouteConfigLoadEnd | ChildActivati...'.

我已经删除了 rxjs6-compat 包,但它没有任何区别。几乎就好像构建认为它拥有比 v5.5 更早的 rxJS 版本。 与 npm install 一起使用的package.json看起来像这样......

"dependencies": {
    "@angular/animations": "^6.0.2",
    "@angular/cdk": "^6.0.2",
    "@angular/common": "^6.0.2",
    "@angular/compiler": "^6.0.2",
    "@angular/core": "^6.0.2",
    "@angular/flex-layout": "^6.0.0-beta.15",
    "@angular/forms": "^6.0.2",
    "@angular/http": "^6.0.2",
    "@angular/material": "^6.0.2",
    "@angular/platform-browser": "^6.0.2",
    "@angular/platform-browser-dynamic": "^6.0.2",
    "@angular/router": "^6.0.2",
    "@ngrx/effects": "^6.0.0-beta.3",
    "@ngrx/entity": "^6.0.0-beta.3",
    "@ngrx/router-store": "^6.0.0-beta.3",
    "@ngrx/store": "^6.0.0-beta.3",
    "@ngrx/store-devtools": "^6.0.0-beta.3",
    "@ngx-translate/core": "^9.0.1",
    "core-js": "^2.5.2",
    "hammerjs": "^2.0.8",
    "lodash": "^4.17.4",
    "material-design-icons-iconfont": "^3.0.3",
    "nsp": "^3.2.1",
    "passport": "^0.4.0",
    "passport-azure-ad": "^3.0.12",
    "rxjs": "^6.1.0",
    "zone.js": "^0.8.26"
  },

rxjs 运算符的导入采用 rxjs6 格式:

import { filter, map, merge, mergeMap } from 'rxjs/operators';

有效但现在给出此错误的语句是:

// Change page title on navigation or language change, based on route data
merge(this.translateService.onLangChange, onNavigationEnd)
  .pipe(
    map(() => {
      let route = this.activatedRoute;
      while (route.firstChild) {
        route = route.firstChild;
      }
      return route;
    }),
    filter(route => route.outlet === 'primary'),
    mergeMap(route => route.data)
  )
  .subscribe(event => {
    const title = event['title'];
    if (title) {
      this.titleService.setTitle(this.translateService.instant(title));
    }
  });

我错过了什么?为什么管道现在在 rxJS 5.5 可以正常工作的情况下导致此错误?

标签: angular6rxjs6

解决方案


您应该像这样导入合并:

import { merge } from 'rxjs';

推荐阅读