Angular v6,rxjs v6错误TS2339:类型'OperatorFunction上不存在属性'pipe'

时间:2018-05-18 14:01:21

标签: angular6 rxjs6

我使用rxjs-lint包和以下命令使用新的管道方法更新了使用Angular 5.5 / rxJS5.5的代码到Angular 6 / rxJS6

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

Imports等已按预期修改,但现在使用RxJS的Angular / 5.5的v5正常运行的代码错误显示错误:

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

我删除了rxjs6-compat包,但没有区别。这几乎就像构建认为它有一个早于rxJS的版本而不是v5.5。与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正常?

3 个答案:

答案 0 :(得分:16)

您应该这样导入合并:

pandas

答案 1 :(得分:1)

应该从“ rxjs / observable” 导入合并运算符。

import { merge } from "rxjs/observable/merge";

答案 2 :(得分:-1)

替换

merge(this.translateService.onLangChange, onNavigationEnd).pipe(

用这个

this.router.events.pipe(filter(event => event instanceof NavigationEnd), 
  map(() => {
    let route = this.activatedRoute;