Skip to content

Commit

Permalink
fix(store): allow default parameters in function action
Browse files Browse the repository at this point in the history
  • Loading branch information
timdeschryver committed Mar 2, 2021
1 parent 84ab6b5 commit 76c6d1f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
10 changes: 8 additions & 2 deletions modules/store/spec/types/action_creator.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,15 +88,21 @@ describe('createAction()', () => {
expectSnippet(`
const foo = createAction('FOO', (type: string) => ({type}));
`).toFail(
/Type '\(type: string\) => \{ type: string; \}' is not assignable to type '"type property is not allowed in action creators"'/
/Type '\{ type: string; \}' is not assignable to type '"type property is not allowed in action creators"'/
);
});

it('should allow foempt', () => {
expectSnippet(`
const foo = createAction('FOO', (bar = 3) => ({bar}));
`).toSucceed();
});

it('should not allow arrays', () => {
expectSnippet(`
const foo = createAction('FOO', () => [ ]);
`).toFail(
/Type '\(\) => any\[\]' is not assignable to type '"arrays are not allowed in action creators"'/
/Type 'any\[\]' is not assignable to type '"arrays are not allowed in action creators"'/
);
});
});
Expand Down
2 changes: 1 addition & 1 deletion modules/store/src/action_creator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export function createAction<
R extends object
>(
type: T,
creator: Creator<P, R> & NotAllowedCheck<R>
creator: Creator<P, R & NotAllowedCheck<R>>
): FunctionWithParametersType<P, R & TypedAction<T>> & TypedAction<T>;
/**
* @description
Expand Down

0 comments on commit 76c6d1f

Please sign in to comment.