combineReducers doesn't infer type

断了今生、忘了曾经 提交于 2020-02-16 03:59:14

问题


I am using combineReducersin my React TypeScript app:

// combinedReducer.ts
import { combineReducers } from 'redux'
import reducer1 from './reducer1'
import reducer2 from './reducer2'

const combinedReducer = combineReducers({
    reducer1,
    reducer2,
})

export default combinedReducer

I understand from redux documentation that combineReducers should infer it's type based on the combined reducers.

However, for me it does not, even though each combined reducer has its return type recognised:

( ReturnType<typeof combidedReducer> is unknown)

What is wrong here?

Here are my maximally simplified reducers:

// reducer1.ts
const initialState: boolean = false

const reducer1 = (state = initialState): boolean => state

export default reducer1
// reducer2.ts
const initialState: boolean = false

const reducer2 = (state = initialState): boolean => state

export default reducer2

来源:https://stackoverflow.com/questions/59768923/combinereducers-doesnt-infer-type

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!