typescript+immutable.js+redux-immutable如何进行类型声明

#1

image

combineReducers这一块的类型如何配置? 实在不行,只能用any大法了!

源代码:

import { combineReducers } from 'redux-immutable'
import { Record, List, Map } from 'immutable'

interface AkamaComponent {
    uuid: any
    componentType: string
    props: Array<string | {}>
}

interface State {
    components: List<Record<AkamaComponent>>
    menuComponents: Map<any, any>
}

const StateRecord = Record({
    components: List([]),
    menuComponents: Map({}),
})

const reducersMap = {
    components: (state: Record<List<AkamaComponent>>, action: any) => {
        return state
    },
    menuComponents: (state: Record<Map<any, any>>, action: any) => {
        return state
    },
}

const rootReducer = combineReducers<State>(reducersMap, StateRecord)

export default rootReducer

测试连接:demo

#2

可以尝试使用immer

#3

immer +1

#4

捕获楼上大佬:blush:

#5

重构代码,都是immutable的数据,还真不好变。我还是any吧。。。。等ts大成,在仔细看看:joy:

#6

解决了。主要还是参照官方的action,reducer,configureStore的组织方式,root类型问题,通过Record<ReturnType<typeof rootReducer>>解决
参照:
Wrong return type of combineReducers