Skip to content

Commit

Permalink
Fixes thunk payloads
Browse files Browse the repository at this point in the history
  • Loading branch information
ctrlplusb committed Jul 23, 2019
1 parent 0bdbdad commit 8b8bdce
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
9 changes: 5 additions & 4 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,11 @@ type ActionMapper<ActionsModel extends object, Depth extends string> = {
any,
any
>
? ActionsModel[P]['actionCreator']
? ActionsModel[P]['payload'] extends void
? () => Promise<ActionsModel[P]['result']>
: (
payload: ActionsModel[P]['payload'],
) => Promise<ActionsModel[P]['result']>
: ActionsModel[P] extends Action<any, any>
? ActionsModel[P]['payload'] extends void
? () => void
Expand Down Expand Up @@ -296,9 +300,6 @@ export type Thunk<
StoreModel extends object = {},
Result = any
> = {
actionCreator: Payload extends void
? () => Promise<Result>
: (payload: Payload) => Promise<Result>;
type: 'thunk';
payload: Payload;
result: Result;
Expand Down
21 changes: 19 additions & 2 deletions src/__tests__/typescript/actions.ts
Original file line number Diff line number Diff line change
@@ -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<string>;
Expand All @@ -13,9 +20,11 @@ type Model = {
stateUndefined: undefined;
stateUnion: string | null;
actionImp: Action<Model, number>;
thunkImp: Thunk<Model, string>;
thunkImp: Thunk<Model, string | undefined | null>;
reducerImp: Reducer<number>;
computedImp: Computed<Model, number>;
// push: Action<Model>;
// pop: Action<Model>;
nested: {
stateArray: Array<string>;
stateBoolean: boolean;
Expand All @@ -35,6 +44,14 @@ type Model = {

type ModelActions = Actions<Model>;

// @ts-ignore
const store = createStore<Model>({});

store.getActions().push();
store.getActions().pop();
store.getActions().actionImp(1);
store.getActions().thunkImp(null);

const assert = {} as ModelActions;

// typings:expect-error
Expand Down

0 comments on commit 8b8bdce

Please sign in to comment.