Skip to content

Commit

Permalink
fix(store): correctly infer action group events defined as empty obje…
Browse files Browse the repository at this point in the history
…ct (#3833)
  • Loading branch information
markostanimirovic authored Apr 15, 2023
1 parent fd8f347 commit dc78447
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
26 changes: 26 additions & 0 deletions modules/store/spec/types/action_group_creator.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(`
Expand Down
8 changes: 5 additions & 3 deletions modules/store/src/action_group_creator_models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,11 @@ export interface ActionGroupConfig<
Events extends Record<string, ActionCreatorProps<unknown> | Creator>
> {
source: Source & StringLiteralCheck<Source, 'source'>;
events: {
[EventName in keyof Events]: Events[EventName] &
EmptyStringCheck<EventName & string, 'event name'> &
events: Events & {
[EventName in keyof Events]: EmptyStringCheck<
EventName & string,
'event name'
> &
StringLiteralCheck<EventName & string, 'event name'> &
ForbiddenCharactersCheck<EventName & string, 'event name'> &
UniqueEventNameCheck<keyof Events & string, EventName & string> &
Expand Down

0 comments on commit dc78447

Please sign in to comment.