reactjs - Redux 的 combineReducers 和 TypeScript

标签 reactjs typescript redux redux-form react-intl

我想在我的 React 应用程序中使用 react-intl-reduxredux-form 但我在使用 时遇到了正确的事情合并 reducer 。我已经尝试了很多东西,但仍然无法弄清楚。

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] Argument of type '{ intl: (state: IntlState, action: IntlAction) => IntlState; }' is not assignable to parameter of type 'ReducersMapObject'. Types of property 'intl' are incompatible. Type '(state: IntlState, action: IntlAction) => IntlState' is not assignable to type 'Reducer'. Types of parameters 'state' and 'state' are incompatible. Type 'IntlState | undefined' is not assignable to type 'IntlState'. Type 'undefined' is not assignable to type 'IntlState'. (alias) function intlReducer(state: IntlState, action: IntlAction): IntlState import 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] Argument of type '{ form: FormReducer; }' is not assignable to parameter of type 'ReducersMapObject'. Types of property 'form' are incompatible. Type 'FormReducer' is not assignable to type 'Reducer'. Types of parameters 'state' and 'state' are incompatible. Type 'FormState | undefined' is not assignable to type 'FormStateMap'. Type 'undefined' is not assignable to type 'FormStateMap'. (alias) const formReducer: FormReducer import formReducer

最佳答案

尝试使用 FormStateMap 而不是 FormState。

关于reactjs - Redux 的 combineReducers 和 TypeScript,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51131546/

相关文章:

javascript - 在组件中使用值之前检查该值是否存在的最佳做法是什么

javascript - 冒泡 componentWillUpdate 和 componentDidUpdate

typescript - 如何使用 webpack 捆绑 puppeteer 进行生产部署?

javascript - 重新映射 json 对象并将它们推送到一个数组中

javascript - 如何在 ReactJS + REDUX 中进入索引路由之前重定向到登录页面

reactjs - 不变失败 : You should not use <Route> outside a <Router>

reactjs - 历史上的 React Router RouteParams

reactjs - Typescript 和 React 使用空类型数组设置初始状态

reactjs - React Redux 工具包 : TypeError: Cannot read property 'value' of undefined

javascript - 如何在react-native中使用thunk?