Skip to content

Commit dc78447

Browse files
fix(store): correctly infer action group events defined as empty object (#3833)
1 parent fd8f347 commit dc78447

File tree

2 files changed

+31
-3
lines changed

2 files changed

+31
-3
lines changed

modules/store/spec/types/action_group_creator.spec.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,32 @@ describe('createActionGroup', () => {
7070
});
7171
});
7272

73+
describe('events', () => {
74+
it('should infer events dictionary', () => {
75+
expectSnippet(`
76+
const authApiActions = createActionGroup({
77+
source: 'Auth API',
78+
events: {
79+
'Login Success': props<{ token: string; }>,
80+
'Login Failure': (message: string) => ({ message }),
81+
},
82+
});
83+
`).toInfer(
84+
'authApiActions',
85+
"ActionGroup<\"Auth API\", { 'Login Success': () => ActionCreatorProps<{ token: string; }>; 'Login Failure': (message: string) => { message: string; }; }>"
86+
);
87+
});
88+
89+
it('should infer events defined as an empty object', () => {
90+
expectSnippet(`
91+
const authApiActions = createActionGroup({
92+
source: 'Auth API',
93+
events: {},
94+
});
95+
`).toInfer('authApiActions', 'ActionGroup<"Auth API", {}>');
96+
});
97+
});
98+
7399
describe('event name', () => {
74100
it('should create action name by camel casing the event name', () => {
75101
expectSnippet(`

modules/store/src/action_group_creator_models.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,11 @@ export interface ActionGroupConfig<
103103
Events extends Record<string, ActionCreatorProps<unknown> | Creator>
104104
> {
105105
source: Source & StringLiteralCheck<Source, 'source'>;
106-
events: {
107-
[EventName in keyof Events]: Events[EventName] &
108-
EmptyStringCheck<EventName & string, 'event name'> &
106+
events: Events & {
107+
[EventName in keyof Events]: EmptyStringCheck<
108+
EventName & string,
109+
'event name'
110+
> &
109111
StringLiteralCheck<EventName & string, 'event name'> &
110112
ForbiddenCharactersCheck<EventName & string, 'event name'> &
111113
UniqueEventNameCheck<keyof Events & string, EventName & string> &

0 commit comments

Comments
 (0)