diff --git a/modules/store/spec/types/action_group_creator.spec.ts b/modules/store/spec/types/action_group_creator.spec.ts index 84ecba35f4..91ef705218 100644 --- a/modules/store/spec/types/action_group_creator.spec.ts +++ b/modules/store/spec/types/action_group_creator.spec.ts @@ -205,6 +205,38 @@ describe('createActionGroup', () => { }); describe('props', () => { + it('should infer when props are typed as union', () => { + expectSnippet(` + const booksApiActions = createActionGroup({ + source: 'Books API', + events: { + 'Load Books Success': props<{ books: string[]; total: number } | { books: symbol[] }>(), + }, + }); + + let loadBooksSuccess: typeof booksApiActions.loadBooksSuccess; + `).toInfer( + 'loadBooksSuccess', + 'ActionCreator<"[Books API] Load Books Success", (props: { books: string[]; total: number; } | { books: symbol[]; }) => ({ books: string[]; total: number; } | { books: symbol[]; }) & TypedAction<"[Books API] Load Books Success">>' + ); + }); + + it('should infer when props are typed as intersection', () => { + expectSnippet(` + const booksApiActions = createActionGroup({ + source: 'Books API', + events: { + 'Load Books Success': props<{ books: string[] } & { total: number }>(), + }, + }); + + let loadBooksSuccess: typeof booksApiActions.loadBooksSuccess; + `).toInfer( + 'loadBooksSuccess', + 'ActionCreator<"[Books API] Load Books Success", (props: { books: string[]; } & { total: number; }) => { books: string[]; } & { total: number; } & TypedAction<"[Books API] Load Books Success">>' + ); + }); + it('should fail when props contain a type property', () => { expectSnippet(` const booksApiActions = createActionGroup({ diff --git a/modules/store/src/action_group_creator_models.ts b/modules/store/src/action_group_creator_models.ts index 0a191715c1..78c64c089d 100644 --- a/modules/store/src/action_group_creator_models.ts +++ b/modules/store/src/action_group_creator_models.ts @@ -78,7 +78,7 @@ type EventCreator< PropsCreator extends ActionCreatorProps | Creator, Type extends string > = PropsCreator extends ActionCreatorProps - ? Props extends void + ? void extends Props ? ActionCreator TypedAction> : ActionCreator< Type,