0

在此处输入图像描述

上面的错误是由 VSCode IDE 抛出的,

在尝试将减速器组合到一个文件中时。

import { ActionReducerMap } from '@ngrx/store';
import { employeeReducer, State } from './store/reducers/employee.reducer';

export interface AppState {
  employee: State;
}

export const appReducer: ActionReducerMap<AppState> = {
  employee: employeeReducer, // Getting IDE error here
};

我的动作看起来像

import { Action } from '@ngrx/store';
import * as EmployeeActions from '../actions/employee.actions';

export interface State {
  name: string;
  designation: string;
}

export const initialState: State = {
  name: '',
  designation: '',
};

export function employeeReducer(
  state = initialState,
  action: EmployeeActions.EmployeeActions
) {
  switch (action.type) {
    case EmployeeActions.GET_EMPLOYEES:
    console.log("The PayLoad", action.payload);
      return {
        ...state,
        name: 'hello',
        designation: 'world',
      };
    default:
      return state;
  }
}

上面的IDE错误可以通过设置来action: Action修复import { Action } from '@ngrx/store'

export function employeeReducer(
  state = initialState,
  action: Action
) {
//...
}

但它会在从动作访问有效负载时抛出错误action.paylod(在减速器中)

无论如何action.type是可以访问的

任何形式的帮助将不胜感激

4

0 回答 0