错误更新@ngrx / effects中的typescript

时间:2017-07-18 23:35:14

标签: angular typescript ngrx ngrx-effects

我有这个错误:' this'类型和行为的背景'不能分配方法'这个'类型'可观察'。物业类型'提升'是不相容的。

此文件:

import { Injectable } from '@angular/core';
import { Effect, Actions } from '@ngrx/effects';
import 'rxjs/add/operator/switchMap';

import { TouristZoneModel } from '../../tourist-zones/shared/tourist-zone.model';
import { TouristZoneActions } from '../actions/touristzone-action-creator';
import { TouristZoneService } from '../../tourist-zones/shared/tourist-zone.service';

@Injectable()
export class TouristZoneEffects {

  @Effect() loadTouristZones$ = this.actions$
    .ofType(TouristZoneActions.LOAD_TOURISTZONES)
    .map(action => action.payload)
    .switchMap((provincePath: string) => this.svc.getTouristZones(provincePath))
    .map((touristzones: TouristZoneModel[]) => this.touristzoneActions.loadTouristZonesSuccess(touristzones));

  @Effect() getTouristZone$ = this.actions$
    .ofType(TouristZoneActions.GET_TOURISTZONE)
    .map(action => action.payload)
    .switchMap((id: string) => this.svc.getTouristZone(id))
    .map((tz: TouristZoneModel) => this.touristzoneActions.getTouristZoneSuccess(tz));

  constructor(
    private actions$: Actions,
    private touristzoneActions: TouristZoneActions,
    private svc: TouristZoneService) { }
}

有人可以向我解释为什么会发生这种情况以及如何解决这个问题?

我读到了这个:Error with Actions observable in @ngrx/effects using TypeScript 2.4.1

但我不明白如何解决我的问题。

我更新 @ngrx / effects:^ 2.0.3→^ 4.0.1 和           typescript ^ 2.3.4→^ 2.4.1

这是当前的package.json:



{
  "name": "trips",
  "version": "1.0.0",
  "description": "QuickStart package.json from the documentation, supplemented with testing support",
  "scripts": {
    "start": "tsc && concurrently \"tsc -w\" \"lite-server\" ",
    "docker-build": "docker build -t ng2-quickstart .",
    "docker": "npm run docker-build && docker run -it --rm -p 3000:3000 -p 3001:3001 ng2-quickstart",
    "pree2e": "npm run webdriver:update",
    "e2e": "tsc && concurrently \"http-server -s\" \"protractor protractor.config.js\" --kill-others --success first",
    "lint": "tslint ./app/**/*.ts -t verbose",
    "lite": "lite-server",
    "test": "tsc && concurrently \"tsc -w\" \"karma start karma.conf.js\"",
    "test-once": "tsc && karma start karma.conf.js --single-run",
    "tsc": "tsc",
    "tsc:w": "tsc -w",
    "webdriver:update": "webdriver-manager update"
  },
  "keywords": [],
  "author": "",
  "licenses": [
    {
      "type": "MIT",
      "url": "https://github.com/angular/angular.io/blob/master/LICENSE"
    }
  ],
  "dependencies": {
    "@agm/core": "^1.0.0-beta.0",
    "@angular/common": "~4.3.0",
    "@angular/compiler": "~4.3.0",
    "@angular/core": "~4.3.0",
    "@angular/forms": "~4.3.0",
    "@angular/http": "~4.3.0",
    "@angular/platform-browser": "~4.3.0",
    "@angular/platform-browser-dynamic": "~4.3.0",
    "@angular/router": "~4.3.0",
    "@angular/upgrade": "~4.3.0",
    "@ngrx/core": "^1.2.0",
    "@ngrx/effects": "^4.0.1",
    "@ngrx/store": "^4.0.0",
    "@types/lodash": "^4.14.70",
    "angular-in-memory-web-api": "~0.3.2",
    "angularfire2": "^4.0.0-rc.1",
    "core-js": "^2.4.1",
    "firebase": "^4.1.3",
    "ngx-pagination": "^3.0.1",
    "reflect-metadata": "^0.1.10",
    "rxjs": "^5.4.2",
    "systemjs": "^0.20.15",
    "zone.js": "^0.8.14"
  },
  "devDependencies": {
    "@types/core-js": "^0.9.42",
    "@types/jasmine": "^2.5.53",
    "@types/node": "^8.0.14",
    "@types/selenium-webdriver": "^3.0.4",
    "autoprefixer": "^7.1.2",
    "bootstrap": "^3.3.7",
    "canonical-path": "0.0.2",
    "concurrently": "^3.5.0",
    "gulp": "^3.9.1",
    "gulp-cssnano": "^2.1.2",
    "gulp-postcss": "^7.0.0",
    "gulp-rename": "^1.2.2",
    "gulp-sourcemaps": "^2.6.0",
    "http-server": "^0.10.0",
    "jasmine-core": "~2.6.4",
    "karma": "^1.7.0",
    "karma-chrome-launcher": "^2.2.0",
    "karma-cli": "^1.0.1",
    "karma-htmlfile-reporter": "^0.3.5",
    "karma-jasmine": "^1.1.0",
    "karma-jasmine-html-reporter": "^0.2.2",
    "lite-server": "^2.3.0",
    "lodash": "^4.17.4",
    "postcss-reporter": "^4.0.0",
    "precss": "^2.0.0",
    "protractor": "5.1.2",
    "rimraf": "^2.6.1",
    "stylelint": "^8.0.0",
    "tslint": "^5.5.0",
    "typescript": "^2.4.1",
    "webdriver-manager": "12.0.6"
  },
  "repository": {}
}




提前致谢。

1 个答案:

答案 0 :(得分:1)

将ngrx / effects更新为2.0.4,将@ ngrx / store更新为2.2.3

"@ngrx/effects": "^2.0.4", "@ngrx/store": "^2.2.3"

moreinfo