Skip to content

Commit

Permalink
fix(store): support using createActionGroup with props typed as uni…
Browse files Browse the repository at this point in the history
…ons (#3713)

Closes #3712
  • Loading branch information
markostanimirovic authored Dec 17, 2022
1 parent 5c87dda commit e75fa1a
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
32 changes: 32 additions & 0 deletions modules/store/spec/types/action_group_creator.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down
2 changes: 1 addition & 1 deletion modules/store/src/action_group_creator_models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ type EventCreator<
PropsCreator extends ActionCreatorProps<unknown> | Creator,
Type extends string
> = PropsCreator extends ActionCreatorProps<infer Props>
? Props extends void
? void extends Props
? ActionCreator<Type, () => TypedAction<Type>>
: ActionCreator<
Type,
Expand Down

0 comments on commit e75fa1a

Please sign in to comment.