Skip to content

Commit

Permalink
fix(store): allow default parameters in function action (#2954)
Browse files Browse the repository at this point in the history
Closes #2948
  • Loading branch information
timdeschryver committed Mar 8, 2021
1 parent 848c031 commit 9b23403
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
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
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 9b23403

Please sign in to comment.