我目前正在做的是: export type Action = { type: 'FOO' } | { type: 'BAR' }export type Thunk = (dispatch: Dispatch, getState: GetState) = Action | Thunk export type Dispatch = ReduxDispatchAction (action: Thunk) = void 但如果您直接
export type Action = { type: 'FOO' } | { type: 'BAR' } export type Thunk = (dispatch: Dispatch, getState: GetState) => Action | Thunk export type Dispatch = ReduxDispatch<Action> & (action: Thunk) => void
但如果您直接在商店发货,那么在没有重新创建商店的情况下将无效:
export type Store = ReduxStore< State,Action>
一般来说,我的thunk解决方案似乎还有其他一些小问题.有没有人有redux-thunk的工作库定义?我找不到任何地方.
我到目前为止找到的最好的例子是Facebook自己的F8应用程序 here中使用的例子.它与你的非常相似:
export type Dispatch = (action: Action | ThunkAction | PromiseAction | Array<Action>) => any; export type GetState = () => Object; export type ThunkAction = (dispatch: Dispatch, getState: GetState) => any; export type PromiseAction = Promise<Action>;
到目前为止,在我的项目中它对我来说效果很好,尽管我不会在任何地方直接在商店发送.