Last active
August 30, 2019 20:00
-
-
Save cellog/684d85c764848a89cc36003900e169d9 to your computer and use it in GitHub Desktop.
Simplified Redux Types
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
interface Action<T = any> { type: T } | |
interface AnyAction extends Action { [extraProps: string]: any } | |
type Reducer<S = any, A extends Action = AnyAction> = ( | |
state: S | undefined, | |
action: A | |
) => S | |
interface Store<S = any, A extends Action = AnyAction> { | |
getState(): S | |
dispatch(action: A): A | |
replaceReducer<NewState = S, NewActions extends A = A>( | |
nextReducer: Reducer<NewState, NewActions> | |
): Store<NewState, NewActions> | |
} | |
export type StoreEnhancer<StoreExt = {}, StateExt = {}> = ( | |
next: StoreEnhancerStoreCreator | |
) => StoreEnhancerStoreCreator<StoreExt, StateExt> | |
export type StoreEnhancerStoreCreator<StoreExt = {}, StateExt = {}> = < | |
S = any, | |
A extends Action = AnyAction | |
>( | |
reducer: Reducer<S, A>, | |
preloadedState?: S | |
) => Store<S & StateExt, A> & StoreExt |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment