Skip to content

Commit

Permalink
fix(reducer): pass arguments to async reducer type
Browse files Browse the repository at this point in the history
  • Loading branch information
omichelsen committed Aug 24, 2019
1 parent 3898430 commit 7fafaec
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
5 changes: 3 additions & 2 deletions src/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,9 @@ export function createAction<Type extends string, Payload, Metadata, U extends a
export interface AsyncActionCreator<
Type extends string,
Payload,
Metadata
> extends ActionCreator<Action<Type, Payload, Metadata>> {
Metadata,
U extends any[]
> extends ActionCreator<Action<Type, Promise<Payload>, Metadata>, U> {
pending: ActionCreator<Action<string>>;
fulfilled: ActionCreator<Action<string, Payload>>;
rejected: ActionCreator<Action<string, Error>>;
Expand Down
5 changes: 3 additions & 2 deletions src/reducers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,9 @@ export interface State<Payload> {
export const asyncReducer = <
Type extends string,
Payload,
Metadata
>(fn: AsyncActionCreator<Type, Payload, Metadata>) => {
Metadata,
U extends any[]
>(fn: AsyncActionCreator<Type, Payload, Metadata, U>) => {
const defaultState: State<Payload> = {};

return createReducer(defaultState, (handleAction) => [
Expand Down
2 changes: 1 addition & 1 deletion test/reducers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ describe('reducers', () => {

describe('asyncReducer', () => {
const action = createAsyncAction(TYPE, () => Promise.resolve(42));
const reducer = asyncReducer(action as any);
const reducer = asyncReducer(action);

it('should return default state if unknown action', () => {
const state = reducer({}, { type: 'UNKNOWN' });
Expand Down

0 comments on commit 7fafaec

Please sign in to comment.