除其他外,类型'Actions <action>'上不存在属性'pipe'

时间:2018-10-09 20:34:24

标签: ngrx ngrx-effects

我注意到了问题990,但是没有解决方法。

项目正在编译,但是我遇到一条错误消息,当我尝试在存储中使用.pipe时,我的效果以及组件中的“ Actions”类型上均不存在“ pipe”属性。但是,当在可观察对象上使用.pipe时,在同一组件中没有出现此问题。

// Lint问题示例在Store / Action类型上不存在

this.item$ = this.store.pipe(select(item));

@Effect({ dispatch: false })
  logout$ = this.actions$.pipe(
    ofType<Logout>(AuthActionTypes.LogoutAction),
    tap(() => {
      localStorage.removeItem(USER);
      this.router.navigate(['/']);
    })
  );

//没问题

this.item$.pipe(takeUntil(this.onDestroy$)).subscribe(status => {

// Package.json,这是带有rxjs 6和NgRx库的Angular 6

  "private": true,
  "dependencies": {
    "@agm/core": "^1.0.0-beta.5",
    "@angular/animations": "^6.1.0",
    "@angular/common": "^6.1.0",
    "@angular/compiler": "^6.1.0",
    "@angular/core": "^6.1.0",
    "@angular/forms": "^6.1.0",
    "@angular/http": "^6.1.0",
    "@angular/platform-browser": "^6.1.0",
    "@angular/platform-browser-dynamic": "^6.1.0",
    "@angular/router": "^6.1.0",
    "@ngrx/effects": "^6.1.0",
    "@ngrx/entity": "^6.1.0",
    "@ngrx/router-store": "^6.1.0",
    "@ngrx/store": "^6.1.0",
    "@ngrx/store-devtools": "^6.1.0",
    "core-js": "^2.5.4",
    "rxjs": "~6.2.0",
    "zone.js": "~0.8.26"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "~0.8.0",
    "@angular/cli": "~6.2.4",
    "@angular/compiler-cli": "^6.1.0",
    "@angular/language-service": "^6.1.0",
    "@ngrx/schematics": "^6.1.0",
    "@types/jasmine": "~2.8.8",
    "@types/jasminewd2": "~2.0.3",
    "@types/node": "~8.9.4",
    "codelyzer": "~4.3.0",
    "jasmine-core": "~2.99.1",
    "jasmine-spec-reporter": "~4.2.1",
    "karma": "~3.0.0",
    "karma-chrome-launcher": "~2.2.0",
    "karma-coverage-istanbul-reporter": "~2.0.1",
    "karma-jasmine": "~1.1.2",
    "karma-jasmine-html-reporter": "^0.2.2",
    "ngrx-store-freeze": "^0.2.4",
    "protractor": "~5.4.0",
    "ts-node": "~7.0.0",
    "tslint": "~5.11.0",
    "typescript": "~2.9.2"
  }
}

1 个答案:

答案 0 :(得分:0)

有相同的错误。就我而言,这是因为我是从“ @ ngrx / store-devtools / src / reducer”而不是“ @ ngrx / effects”导入动作

import { Injectable } from '@angular/core';
import { createEffect } from '@ngrx/effects';
//import { Actions } from '@ngrx/store-devtools/src/reducer'; --> wrong
import { Actions, ofType } from '@ngrx/effects';
import { map, mergeMap } from 'rxjs/operators';
import { ProductService } from '../product.service';
import * as ProductActions from './product.actions';

    @Injectable()
    export class ProductEffects {
        constructor(private actions$: Actions,
            private productsService: ProductService) { }
    
        loadProducts$ = createEffect(() => {
            return this.actions$.pipe(
                ofType(ProductActions.loadProducts),
                mergeMap(() => this.productsService.getProducts().pipe(
                    map(products => ProductActions.loadProductsSuccess({ products }))
                ))
            )
        })
    
    }