From dc78447327fdf1f15ff862f2914d762040ae9825 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20Stanimirovi=C4=87?= Date: Sun, 16 Apr 2023 00:36:48 +0200 Subject: [PATCH] fix(store): correctly infer action group events defined as empty object (#3833) --- .../spec/types/action_group_creator.spec.ts | 26 +++++++++++++++++++ .../store/src/action_group_creator_models.ts | 8 +++--- 2 files changed, 31 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..39a8ebe984 100644 --- a/modules/store/spec/types/action_group_creator.spec.ts +++ b/modules/store/spec/types/action_group_creator.spec.ts @@ -70,6 +70,32 @@ 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", {}>'); + }); + }); + 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 &