Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(store): correctly infer action group events defined as empty object #3833

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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', () => {
markostanimirovic marked this conversation as resolved.
Show resolved Hide resolved
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