Skip to content

Commit

Permalink
libdefs: Hard-code redux-thunk support into redux-mock-store.
Browse files Browse the repository at this point in the history
As foreshadowed in the preceding commits, we can't really expect a
FlowTyped-hosted libdef to have the flexibility to give us the right
types for Dispatch on the condition that we pass `thunk` as a piece
of middleware.

We're decidedly using `thunk`, so, hard-code support for it here by
allowing dispatch to be called with a redux-thunk async action.

We're pretty consistent with having correct types for such an
action, so not much is lost by typing its arguments loosely as
`Function, Function`, and from some attempts, it seems much easier
than nailing down something exactly right.

[cherry-picked from zulip#4171]
  • Loading branch information
chrisbobbe committed Jul 10, 2020
1 parent 83d2409 commit aea10d7
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions flow-typed/redux-mock-store_v1.2.x.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,15 @@ declare module 'redux-mock-store' {
*/

declare type mockStore = { <S, A>(state: S): mockStoreWithoutMiddleware<S, A>, ... };
declare type DispatchAPI<A> = (action: A) => A;
declare type Dispatch<A: $ReadOnly<{ type: string, ... }>> = DispatchAPI<A>;
declare interface Dispatch<S, A> {
(action: A): A;
<T>((Function, Function) => T): T;
}

declare type mockStoreWithoutMiddleware<S, A> = {
getState(): S,
getActions(): Array<A>,
dispatch: Dispatch<A>,
dispatch: Dispatch<S, A>,
clearActions(): void,
subscribe(callback: () => void): () => void,
replaceReducer(nextReducer: Function): void,
Expand Down

0 comments on commit aea10d7

Please sign in to comment.