diff --git a/index.d.ts b/index.d.ts index 3a8413fad9..45a11307d3 100644 --- a/index.d.ts +++ b/index.d.ts @@ -194,9 +194,8 @@ export interface Store { * @template S State object type. */ export interface StoreCreator { - (reducer: Reducer, enhancer?: StoreEnhancer): Store; - (reducer: Reducer, initialState: S, - enhancer?: StoreEnhancer): Store; + (reducer: Reducer, enhancer?: StoreEnhancer): Store; + (reducer: Reducer, initialState: S, enhancer?: StoreEnhancer): Store; } /** @@ -217,7 +216,9 @@ export interface StoreCreator { * without the app being aware it is happening. Amusingly, the Redux * middleware implementation is itself a store enhancer. */ -export type StoreEnhancer = (next: StoreCreator) => StoreCreator; +export type StoreEnhancer = (next: StoreEnhancerStoreCreator) => StoreEnhancerStoreCreator; +export type GenericStoreEnhancer = (next: StoreEnhancerStoreCreator) => StoreEnhancerStoreCreator; +export type StoreEnhancerStoreCreator = (reducer: Reducer, initialState: S) => Store; /** * Creates a Redux store that holds the state tree. @@ -287,7 +288,7 @@ export interface Middleware { * @param middlewares The middleware chain to be applied. * @returns A store enhancer applying the middleware. */ -export function applyMiddleware(...middlewares: Middleware[]): StoreEnhancer; +export function applyMiddleware(...middlewares: Middleware[]): GenericStoreEnhancer; /* action creators */ diff --git a/test/typescript/store.ts b/test/typescript/store.ts index bfb758671b..3cd4ebe941 100644 --- a/test/typescript/store.ts +++ b/test/typescript/store.ts @@ -1,5 +1,5 @@ import { - Store, createStore, Reducer, Action, StoreEnhancer, + Store, createStore, Reducer, Action, StoreEnhancer, GenericStoreEnhancer, StoreCreator, Unsubscribe } from "../../index.d.ts"; @@ -21,13 +21,15 @@ const storeWithInitialState: Store = createStore(reducer, { todos: [] }); -const enhancer: StoreEnhancer = (next: StoreCreator) => next; +const genericEnhancer: GenericStoreEnhancer = next => next; +const specificEnhencer: StoreEnhancer = next => next; -const storeWithEnhancer: Store = createStore(reducer, enhancer); +const storeWithGenericEnhancer: Store = createStore(reducer, genericEnhancer); +const storeWithSpecificEnhancer: Store = createStore(reducer, specificEnhencer); const storeWithInitialStateAndEnhancer: Store = createStore(reducer, { todos: [] -}, enhancer); +}, genericEnhancer); /* dispatch */