Created
September 2, 2019 15:41
-
-
Save cellog/7f387bf7b5038adce3e6f8ad7b4f54f6 to your computer and use it in GitHub Desktop.
Better types, with inference
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, | |
StateExt = BaseType<S>, | |
Ext = {} | |
> { { | |
getState(): S & StateExt | |
dispatch(action: A): A | |
replaceReducer<NewState, NewActions extends Action>( | |
nextReducer: Reducer<NewState, NewActions> | |
): Store<NewState & StateExt, NewActions, StateExt, Ext> & Ext | |
} | |
export type StoreEnhancer<StoreExt = {}, StateExt = {}> = ( | |
next: StoreEnhancerStoreCreator<StoreExt, StateExt> | |
) => StoreEnhancerStoreCreator<StoreExt, StateExt> | |
export type StoreEnhancerStoreCreator<StoreExt = {}, StateExt = {}> = < | |
S = any, | |
A extends Action = AnyAction | |
>( | |
reducer: Reducer<S, A>, | |
preloadedState?: S | |
) => Store<S & StateExt, A, StateExt, Ext> & StoreExt |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment