Skip to content

Instantly share code, notes, and snippets.

@kangax
Last active September 19, 2019 11:37
Show Gist options
  • Save kangax/f060f1c655431052501de036f30f513d to your computer and use it in GitHub Desktop.
Save kangax/f060f1c655431052501de036f30f513d to your computer and use it in GitHub Desktop.
import type { GlobalState } from 'redux/modules';
export type ExtractReturn<Fn> = $Call<<T>((...Iterable<any>) => T) => T, Fn>;
// ...
export type BaseAction = $ReadOnly<{ type: string, error?: boolean }>;
// ...
export type GetState<S> = () => S;
export type GetGlobalState = GetState<GlobalState>;
export type PromiseAction<A: BaseAction> = Promise<A>;
export type ThunkAction<A, S = GlobalState> = (dispatch: Dispatch<A>, getState: GetState<S>) => any;
export type Dispatch<A: BaseAction, S = GlobalState> = (
action: A | ThunkAction<A, S> | PromiseAction<A> | Array<A>
) => Promise<*>;
// ...
export type DispatchLoose<A> = (
action: A | ThunkAction<A> | PromiseAction<A> | Array<A>
) => Promise<any>;
// ...
export type ExtractReturnWithDispatch = <V>((...args: Array<*>) => V) => DispatchLoose<V>;
export type ReduxProps<M, D> = $ReadOnly<{| ...ExtractReturn<M>, ...ExtractReturn<D> |}>;
export type ReduxPropsWithDispatchShorthand<M, D> = $ReadOnly<{|
...ExtractReturn<M>,
...$ObjMap<D, ExtractReturnWithDispatch>,
|}>;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment