Redux的CombineReducers和TypeScript

时间:2018-07-02 08:03:35

标签: reactjs typescript redux redux-form react-intl

我想在我的react应用程序中使用react-intl-reduxredux-form,但是在使用combineReducers时做正确的事情很麻烦。我已经尝试了很多事情,但仍然无法解决。

react-intl-redux

import { combineReducers } from "redux";
import { intlReducer, IntlState } from "react-intl-redux";

export interface IAppState {
  intl: IntlState;
}

export default combineReducers<IAppState>({
  intl: intlReducer
});
  

[ts]类型为'{intl:的参数(状态:IntlState,操作:IntlAction)   => IntlState; }”不能分配给“ ReducersMapObject”类型的参数。属性“ intl”的类型   不兼容。       类型'(状态:IntlState,操作:IntlAction)=> IntlState'不能分配给类型'Reducer'。         参数“状态”和“状态”的类型不兼容。           输入'IntlState |未定义”不能分配给“ IntlState”类型。             类型“未定义”不能分配给类型“ IntlState”。 (别名)函数intlReducer(状态:IntlState,操作:IntlAction):   IntlState导入intlReducer

redux格式

import { combineReducers } from "redux";
import { reducer as formReducer, FormState } from "redux-form";

export interface IAppState {
  form: FormState;
}

export default combineReducers<IAppState>({
  form: formReducer
});
  

[ts]类型'{的参数形式:FormReducer; }'不可分配给   'ReducersMapObject'类型的参数。种类   属性“ form”不兼容。       类型“ FormReducer”不可分配给类型“ Reducer”。         参数“状态”和“状态”的类型不兼容。           输入'FormState |未定义”无法分配给“ FormStateMap”类型。             类型“未定义”不能分配给类型“ FormStateMap”。 (别名)const formReducer:FormReducer导入formReducer

3 个答案:

答案 0 :(得分:3)

在我的情况下,创建减速器时,我是从Reducer包而不是react包中导入类型redux

  

转到显示错误的化简器定义,然后   import {Reducer} from 'redux'

答案 1 :(得分:2)

尝试使用FormStateMap而不是FormState。

答案 2 :(得分:-5)

我最近遇到了这个问题,并且我修复了禁用strictFunctionTypes tsconfig规则的问题。

相关问题