Skip to content

Commit 63510a8

Browse files
fix(store): prevent unexpected behavior of {} as a props type (#2728)
1 parent b06084a commit 63510a8

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,21 @@ describe('createAction()', () => {
4343
);
4444
});
4545

46-
it('should not allow ararys', () => {
46+
it('should not allow arrays', () => {
4747
expectSnippet(`
4848
const foo = createAction('FOO', props<[]>());
4949
`).toFail(
5050
/Type 'Props<\[\]>' is not assignable to type '"arrays are not allowed in action creators"'/
5151
);
5252
});
53+
54+
it('should not allow empty objects', () => {
55+
expectSnippet(`
56+
const foo = createAction('FOO', props<{}>());
57+
`).toFail(
58+
/Type 'Props<\{\}>' is not assignable to type '"empty objects are not allowed in action creators"'/
59+
);
60+
});
5361
});
5462

5563
describe('with function', () => {

modules/store/src/models.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@ export const typePropertyIsNotAllowedMsg =
6161
'type property is not allowed in action creators';
6262
type TypePropertyIsNotAllowed = typeof typePropertyIsNotAllowedMsg;
6363

64+
export const emptyObjectsAreNotAllowedMsg =
65+
'empty objects are not allowed in action creators';
66+
type EmptyObjectsAreNotAllowed = typeof emptyObjectsAreNotAllowedMsg;
67+
6468
export type FunctionIsNotAllowed<
6569
T,
6670
ErrorMessage extends string
@@ -77,6 +81,8 @@ export type NotAllowedCheck<T extends object> = T extends any[]
7781
? ArraysAreNotAllowed
7882
: T extends { type: any }
7983
? TypePropertyIsNotAllowed
84+
: keyof T extends never
85+
? EmptyObjectsAreNotAllowed
8086
: unknown;
8187

8288
/**

0 commit comments

Comments
 (0)