繁体   English   中英

combineReducers 返回类型被推断为任何类型

[英]combineReducers return type is inferred to have type any

我在 JSDocs 上使用 typescript 并且我在输入我的应用程序的根 state 时遇到了麻烦。 Following redux documentation about how to use it with typescript, I try to use the return type of my root reducer as the root state state but it infers to be any. 我不确定这是否只是我的 redux 版本上的错误或什么。 这是我的代码片段:

import { combineReducers } from 'redux';
import { routerReducer } from 'react-router-redux';

const homeReducer = (state: {cool: boolean}) => state

const reducerMap = {
  router: routerReducer,
  home: homeReducer,
};

/** @typedef {ReturnType<typeof rootReducer>} RootState*/

const rootReducer = combineReducers(reducerMap);
export default rootReducer;

我从中得到的类型是type RootState = any 我的redux版本是3.7.2

typescript游乐场

因此,看起来 redux 版本 3.7.2 不包含正确的类型。 希望它很容易升级到 4.0.5,现在我发布的类型是正确的。 如果有人有兴趣查看此 PR 上的升级更改: 合并请求

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM