From 9b234033b5c24c8686bdac7780a7e066d795153c Mon Sep 17 00:00:00 2001 From: Tim Deschryver <28659384+timdeschryver@users.noreply.github.com> Date: Tue, 9 Mar 2021 00:09:25 +0100 Subject: [PATCH] fix(store): allow default parameters in function action (#2954) Closes #2948 --- modules/store/spec/types/action_creator.spec.ts | 10 ++++++++-- modules/store/src/action_creator.ts | 2 +- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/modules/store/spec/types/action_creator.spec.ts b/modules/store/spec/types/action_creator.spec.ts index 2b4052aeae..b1488374b2 100644 --- a/modules/store/spec/types/action_creator.spec.ts +++ b/modules/store/spec/types/action_creator.spec.ts @@ -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"'/ ); }); }); diff --git a/modules/store/src/action_creator.ts b/modules/store/src/action_creator.ts index a3d49fffe1..7e24e045c9 100644 --- a/modules/store/src/action_creator.ts +++ b/modules/store/src/action_creator.ts @@ -24,7 +24,7 @@ export function createAction< R extends object >( type: T, - creator: Creator & NotAllowedCheck + creator: Creator> ): FunctionWithParametersType> & TypedAction; /** * @description