Skip to content

Instantly share code, notes, and snippets.

@kangax

kangax/redux_types.js

Last active Sep 19, 2019
Embed
What would you like to do?
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
You can’t perform that action at this time.