Skip to content

Instantly share code, notes, and snippets.

@cellog
Last active August 30, 2019 20:00
Show Gist options
  • Save cellog/684d85c764848a89cc36003900e169d9 to your computer and use it in GitHub Desktop.
Save cellog/684d85c764848a89cc36003900e169d9 to your computer and use it in GitHub Desktop.
Simplified Redux Types
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