From 0c2ac9604d4e8a281a30c377b04837eb9f8c4db8 Mon Sep 17 00:00:00 2001 From: Walker Henderson Date: Thu, 10 May 2018 21:51:44 -0700 Subject: [PATCH] Use same return type for both StoreCreator signatures in TS typings --- index.d.ts | 2 +- test/typescript/store.ts | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/index.d.ts b/index.d.ts index f8b7d22dc9..bcc44bffa8 100644 --- a/index.d.ts +++ b/index.d.ts @@ -220,7 +220,7 @@ export type DeepPartial = { [K in keyof T]?: DeepPartial }; */ export interface StoreCreator { (reducer: Reducer, enhancer?: StoreEnhancer): Store & Ext; - (reducer: Reducer, preloadedState: DeepPartial, enhancer?: StoreEnhancer): Store & Ext; + (reducer: Reducer, preloadedState: DeepPartial, enhancer?: StoreEnhancer): Store & Ext; } /** diff --git a/test/typescript/store.ts b/test/typescript/store.ts index 7fa642259f..724c6a5046 100644 --- a/test/typescript/store.ts +++ b/test/typescript/store.ts @@ -12,6 +12,11 @@ type State = { }; } +interface DerivedAction extends Action { + type: 'a', + b: 'b', +} + const reducer: Reducer = (state: State | undefined = { a: 'a', b: { @@ -22,6 +27,18 @@ const reducer: Reducer = (state: State | undefined = { return state; }; +const reducerWithAction: Reducer = (state: State | undefined = { + a: 'a', + b: { + c: 'c', + d: 'd', + }, +}, action: DerivedAction): State => { + return state; +}; + +const funcWithStore = (store: Store) => {}; + /* createStore */ const store: Store = createStore(reducer); @@ -30,6 +47,13 @@ const storeWithPreloadedState: Store = createStore(reducer, { b: {c: 'c'} }); +const storeWithActionReducer = createStore(reducerWithAction); +const storeWithActionReducerAndPreloadedState = createStore(reducerWithAction, { + b: {c: 'c'}, +}); +funcWithStore(storeWithActionReducer); +funcWithStore(storeWithActionReducerAndPreloadedState); + const enhancer: StoreEnhancer = next => next; const storeWithSpecificEnhancer: Store = createStore(reducer, enhancer);