Skip to content

Commit

Permalink
Update typings for Dispatch and StoreCreator
Browse files Browse the repository at this point in the history
  • Loading branch information
aikoven committed Feb 17, 2016
1 parent 889030c commit c01501f
Showing 1 changed file with 18 additions and 9 deletions.
27 changes: 18 additions & 9 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
export interface ActionCreator {
(...args: any[]): any;
export interface Action {
type: string;
}

export type Reducer<S> = (state: S, action: any) => S;
export type Reducer<S> = (state: S, action: Action) => S;

export type Dispatch = (action: any) => any;

Expand All @@ -15,25 +15,34 @@ export interface Middleware {
<S>(api: MiddlewareAPI<S>): (next: Dispatch) => Dispatch;
}

export class Store<S> {
export interface Store<S> {
dispatch: Dispatch;
getState: () => S;
subscribe: (listener: () => void) => () => void;
replaceReducer: (reducer: Reducer<S>) => void;
}

export type StoreCreator<S> = (reducer: Reducer<S>, initialState?: S) => Store<S>;
export interface StoreCreator<S> {
(reducer: Reducer<S>): Store<S>;
(reducer: Reducer<S>, enhancer: StoreEnhancer): Store<S>;
(reducer: Reducer<S>, initialState: S): Store<S>;
(reducer: Reducer<S>, initialState: S, enhancer: StoreEnhancer): Store<S>;
}

export type StoreEnhancer = <S>(next: StoreCreator<S>) => StoreCreator<S>;

export function createStore<S>(reducer: Reducer<S>, initialState?: S,
enhancer?: StoreEnhancer): Store<S>;

export function bindActionCreators<T extends ActionCreator|{[key: string]: ActionCreator}>(actionCreators: T, dispatch: Dispatch): T;
export const createStore: StoreCreator;

export function combineReducers<S>(reducers: {[key: string]: Reducer<any>}): Reducer<S>;
export function applyMiddleware<S>(...middlewares: Middleware[]): StoreEnhancer;


export interface ActionCreator {
(...args: any[]): any;
}

export function bindActionCreators<T extends ActionCreator|{[key: string]: ActionCreator}>(actionCreators: T, dispatch: Dispatch): T;

// from DefinitelyTyped/compose-function
// Hardcoded signatures for 2-4 parameters
export function compose<A, B, C>(f1: (b: B) => C,
Expand Down

0 comments on commit c01501f

Please sign in to comment.