Skip to content

Commit 9b23403

Browse files
fix(store): allow default parameters in function action (#2954)
Closes #2948
1 parent 848c031 commit 9b23403

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

modules/store/spec/types/action_creator.spec.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,15 +88,21 @@ describe('createAction()', () => {
8888
expectSnippet(`
8989
const foo = createAction('FOO', (type: string) => ({type}));
9090
`).toFail(
91-
/Type '\(type: string\) => \{ type: string; \}' is not assignable to type '"type property is not allowed in action creators"'/
91+
/Type '\{ type: string; \}' is not assignable to type '"type property is not allowed in action creators"'/
9292
);
9393
});
9494

95+
it('should allow foempt', () => {
96+
expectSnippet(`
97+
const foo = createAction('FOO', (bar = 3) => ({bar}));
98+
`).toSucceed();
99+
});
100+
95101
it('should not allow arrays', () => {
96102
expectSnippet(`
97103
const foo = createAction('FOO', () => [ ]);
98104
`).toFail(
99-
/Type '\(\) => any\[\]' is not assignable to type '"arrays are not allowed in action creators"'/
105+
/Type 'any\[\]' is not assignable to type '"arrays are not allowed in action creators"'/
100106
);
101107
});
102108
});

modules/store/src/action_creator.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export function createAction<
2424
R extends object
2525
>(
2626
type: T,
27-
creator: Creator<P, R> & NotAllowedCheck<R>
27+
creator: Creator<P, R & NotAllowedCheck<R>>
2828
): FunctionWithParametersType<P, R & TypedAction<T>> & TypedAction<T>;
2929
/**
3030
* @description

0 commit comments

Comments
 (0)