From 8b8bdce969de70ef55df9ed23811f9fc5badab8c Mon Sep 17 00:00:00 2001 From: Sean Matheson Date: Thu, 4 Jul 2019 02:23:53 +0100 Subject: [PATCH] Fixes thunk payloads --- index.d.ts | 9 +++++---- src/__tests__/typescript/actions.ts | 21 +++++++++++++++++++-- 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/index.d.ts b/index.d.ts index 6126c3938..8a72c2cb1 100644 --- a/index.d.ts +++ b/index.d.ts @@ -67,7 +67,11 @@ type ActionMapper = { any, any > - ? ActionsModel[P]['actionCreator'] + ? ActionsModel[P]['payload'] extends void + ? () => Promise + : ( + payload: ActionsModel[P]['payload'], + ) => Promise : ActionsModel[P] extends Action ? ActionsModel[P]['payload'] extends void ? () => void @@ -296,9 +300,6 @@ export type Thunk< StoreModel extends object = {}, Result = any > = { - actionCreator: Payload extends void - ? () => Promise - : (payload: Payload) => Promise; type: 'thunk'; payload: Payload; result: Result; diff --git a/src/__tests__/typescript/actions.ts b/src/__tests__/typescript/actions.ts index fdaf0903b..1d9e6ea75 100644 --- a/src/__tests__/typescript/actions.ts +++ b/src/__tests__/typescript/actions.ts @@ -1,6 +1,13 @@ /* eslint-disable */ -import { Actions, Thunk, Action, Reducer, Computed } from 'easy-peasy'; +import { + createStore, + Actions, + Thunk, + Action, + Reducer, + Computed, +} from 'easy-peasy'; type Model = { stateArray: Array; @@ -13,9 +20,11 @@ type Model = { stateUndefined: undefined; stateUnion: string | null; actionImp: Action; - thunkImp: Thunk; + thunkImp: Thunk; reducerImp: Reducer; computedImp: Computed; + // push: Action; + // pop: Action; nested: { stateArray: Array; stateBoolean: boolean; @@ -35,6 +44,14 @@ type Model = { type ModelActions = Actions; +// @ts-ignore +const store = createStore({}); + +store.getActions().push(); +store.getActions().pop(); +store.getActions().actionImp(1); +store.getActions().thunkImp(null); + const assert = {} as ModelActions; // typings:expect-error