初始化程序类型不能分配给变量类型ActionReducerMap <state>

时间:2019-05-15 11:27:58

标签: angular ngrx-store

即使标题出现此错误,代码也能正常工作,它突然发生了,我没有安装任何新软件包或没有更新任何现有软件包。为什么会这样呢?逻辑的每个部分都按预期工作,即使测试也不会失败。

代码:

import { ActionReducerMap, createFeatureSelector, createSelector } from '@ngrx/store'

import * as fromAuth from '../auth/auth-store/auth.reducers';
import * as fromUserDetails from '../auth/user/user-store/user.reducers';
import * as fromUI from '../shared/ui/ui-store/ui.reducer';

export interface State {
    auth: fromAuth.State;
    userDetails: fromUserDetails.State;
    ui: fromUI.State;
}

export const reducers: ActionReducerMap<State> = {
    auth: fromAuth.authReducer,
    userDetails: fromUserDetails.userDetailsReducer,
    ui: fromUI.uiReducer
};

每个reducer都以相同的方式初始化和导出,这是一个示例:

import { AuthActions, SIGNIN_USER } from './auth.actions';

export interface State {
    isAuth: boolean
    userRole: string
}

export const initialState: State = {
    isAuth: false,
    userRole: null
}

export function authReducer(state = initialState, action: AuthActions) {
    switch (action.type) {
        case SIGNIN_USER: {
            return {
                ...state,
                isAuth: true
            }   
        }
        default:
            return {
                ...state
            }
    }
}

package.json

{
  "name": "grades-app-front",
  "version": "0.0.0",
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e"
  },
  "private": true,
  "dependencies": {
    "@angular/animations": "^7.2.5",
    "@angular/cdk": "^7.3.2",
    "@angular/common": "^7.2.5",
    "@angular/compiler": "^7.2.5",
    "@angular/core": "^7.2.5",
    "@angular/flex-layout": "^7.0.0-beta.23",
    "@angular/forms": "^7.2.5",
    "@angular/material": "7.3.0",
    "@angular/platform-browser": "^7.2.5",
    "@angular/platform-browser-dynamic": "^7.2.5",
    "@angular/router": "^7.2.5",
    "@fortawesome/angular-fontawesome": "^0.3.0",
    "@fortawesome/fontawesome-free": "^5.7.2",
    "@ngrx/effects": "^7.2.0",
    "@ngrx/store": "^7.2.0",
    "@ngrx/store-devtools": "^7.2.0",
    "angular-font-awesome": "^3.1.2",
    "bootstrap": "^4.3.1",
    "core-js": "^2.6.5",
    "font-awesome": "^4.7.0",
    "hammerjs": "^2.0.8",
    "jasmine-marbles": "^0.4.1",
    "ngx-infinite-scroll": "^7.1.0",
    "rxjs": "~6.3.3",
    "rxjs-compat": "^6.4.0",
    "tslib": "^1.9.0",
    "zone.js": "^0.8.29"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "^0.12.4",
    "@angular/cli": "^7.3.2",
    "@angular/compiler-cli": "^7.2.5",
    "@angular/language-service": "^7.2.5",
    "@types/core-js": "^2.5.0",
    "@types/jasmine": "^2.8.16",
    "@types/jasminewd2": "~2.0.3",
    "@types/node": "~8.9.4",
    "codelyzer": "~4.5.0",
    "jasmine": "^2.99.0",
    "jasmine-core": "~2.99.1",
    "jasmine-spec-reporter": "~4.2.1",
    "jest": "^24.1.0",
    "jest-preset-angular": "^6.0.2",
    "karma": "^4.0.0",
    "karma-chrome-launcher": "~2.2.0",
    "karma-coverage": "^1.1.2",
    "karma-coverage-istanbul-reporter": "^2.0.5",
    "karma-jasmine": "~1.1.2",
    "karma-jasmine-html-reporter": "^0.2.2",
    "protractor": "~5.4.0",
    "ts-node": "~7.0.0",
    "tslint": "~5.11.0",
    "typescript": "~3.2.2"
  }
}

有什么想法吗?预先谢谢你。

0 个答案:

没有答案