简体   繁体   English

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

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

I am using typescript on JSDocs and I am having a bad time typing the root state of my application.我在 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. 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. I'm not sure if this is just a bug on my redux version or what.我不确定这是否只是我的 redux 版本上的错误或什么。 Here is my code snippet:这是我的代码片段:

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;

The type I'm getting out of this is type RootState = any .我从中得到的类型是type RootState = any My redux version is 3.7.2我的redux版本是3.7.2

typescript playground typescript游乐场

So, looks that redux version 3.7.2 doesn't include proper types.因此,看起来 redux 版本 3.7.2 不包含正确的类型。 Hopefully it was easy to upgrade it to 4.0.5 and now the types I posted are correct.希望它很容易升级到 4.0.5,现在我发布的类型是正确的。 If anyone is interested in taking a look on the upgrade changes are on this PR: merge request如果有人有兴趣查看此 PR 上的升级更改: 合并请求

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

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