From 4288d7ff3491ede09536e2ab29858543ada145d4 Mon Sep 17 00:00:00 2001 From: markostanimirovic Date: Wed, 5 Apr 2023 22:58:08 +0200 Subject: [PATCH 1/2] fix(store): correctly infer action group events defined as empty object --- modules/store/spec/types/action_group_creator.spec.ts | 11 +++++++++++ modules/store/src/action_group_creator_models.ts | 8 +++++--- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/modules/store/spec/types/action_group_creator.spec.ts b/modules/store/spec/types/action_group_creator.spec.ts index 91ef705218..6bc624e809 100644 --- a/modules/store/spec/types/action_group_creator.spec.ts +++ b/modules/store/spec/types/action_group_creator.spec.ts @@ -70,6 +70,17 @@ describe('createActionGroup', () => { }); }); + describe('events', () => { + it('should infer events defined as an empty object', () => { + expectSnippet(` + const authApiActions = createActionGroup({ + source: 'Auth API', + events: {}, + }); + `).toInfer('authApiActions', 'ActionGroup<"Auth API", {}>'); + }); + }); + describe('event name', () => { it('should create action name by camel casing the event name', () => { expectSnippet(` diff --git a/modules/store/src/action_group_creator_models.ts b/modules/store/src/action_group_creator_models.ts index 78c64c089d..2e96aa837f 100644 --- a/modules/store/src/action_group_creator_models.ts +++ b/modules/store/src/action_group_creator_models.ts @@ -103,9 +103,11 @@ export interface ActionGroupConfig< Events extends Record | Creator> > { source: Source & StringLiteralCheck; - events: { - [EventName in keyof Events]: Events[EventName] & - EmptyStringCheck & + events: Events & { + [EventName in keyof Events]: EmptyStringCheck< + EventName & string, + 'event name' + > & StringLiteralCheck & ForbiddenCharactersCheck & UniqueEventNameCheck & From ab6b5bfce95996c7e2d7b43453d9224bac677505 Mon Sep 17 00:00:00 2001 From: markostanimirovic Date: Sun, 9 Apr 2023 16:10:03 +0200 Subject: [PATCH 2/2] test(store): add type test for events dictionary --- .../spec/types/action_group_creator.spec.ts | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/modules/store/spec/types/action_group_creator.spec.ts b/modules/store/spec/types/action_group_creator.spec.ts index 6bc624e809..39a8ebe984 100644 --- a/modules/store/spec/types/action_group_creator.spec.ts +++ b/modules/store/spec/types/action_group_creator.spec.ts @@ -71,13 +71,28 @@ describe('createActionGroup', () => { }); describe('events', () => { + it('should infer events dictionary', () => { + expectSnippet(` + const authApiActions = createActionGroup({ + source: 'Auth API', + events: { + 'Login Success': props<{ token: string; }>, + 'Login Failure': (message: string) => ({ message }), + }, + }); + `).toInfer( + 'authApiActions', + "ActionGroup<\"Auth API\", { 'Login Success': () => ActionCreatorProps<{ token: string; }>; 'Login Failure': (message: string) => { message: string; }; }>" + ); + }); + it('should infer events defined as an empty object', () => { expectSnippet(` const authApiActions = createActionGroup({ source: 'Auth API', events: {}, }); - `).toInfer('authApiActions', 'ActionGroup<"Auth API", {}>'); + `).toInfer('authApiActions', 'ActionGroup<"Auth API", {}>'); }); });