传播类型只能使用通用类型从对象类型创建

时间:2018-10-18 09:08:37

标签: typescript redux

在ActionCollection也是对象的情况下如何解决此问题

源代码:

type ActionHandler = (...args: any) => IPayloadAction<any>
type ActionCollection = { [key: string]: ActionHandler }

export const buildResourceFromRedux = <A extends ActionCollection, S>(name: string, reduxModule: IRedux<A, S>) => {
    return {
        redux: reduxModule,
        getResource: () => {
            const store = getStore(reduxModule.reducer, reduxModule.saga, { name })
            // Action
            const action = dispatchAction(reduxModule.action, store.dispatch) as A

            return {
                store,
                ...action,  ///////////////////////// Err here
                ...reduxModule,
            }
        },
    }
}

我这样称呼数据的数据

buildResourceFromRedux('aUnitName', {
    action: {
        query: () => ({
            type: 'QUERY',
        }),
        get: (id: string) => ({
            type: 'GET',
            payload: {
                id,
            }
        })
    },
    saga: watchSaga*() {...}
    reducer: (state, actions: Action<any>) => state
})

我正在使用打字稿3.1.2。

0 个答案:

没有答案