Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(store): allow default parameters in function action #2954

Merged
merged 1 commit into from
Mar 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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