Skip to content

Commit

Permalink
fix(store): add not allowed check to action creator config (#2313)
Browse files Browse the repository at this point in the history
  • Loading branch information
timdeschryver authored and brandonroberts committed Jan 11, 2020
1 parent 33241cb commit f6336d5
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
8 changes: 4 additions & 4 deletions modules/store/spec/types/action_creator.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,15 @@ describe('createAction()', () => {
expectSnippet(`
const foo = createAction('FOO', props<{ type: number }>());
`).toFail(
/Argument of type '"type property is not allowed in action creators"' is not assignable to parameter of type/
/ Type 'Props<\{ type: number; \}>' is not assignable to type '"type property is not allowed in action creators"'/
);
});

it('should not allow ararys', () => {
expectSnippet(`
const foo = createAction('FOO', props<[]>());
`).toFail(
/Argument of type '"arrays are not allowed in action creators"' is not assignable to parameter of type/
/Type 'Props<\[\]>' is not assignable to type '"arrays are not allowed in action creators"'/
);
});
});
Expand Down Expand Up @@ -80,15 +80,15 @@ describe('createAction()', () => {
expectSnippet(`
const foo = createAction('FOO', (type: string) => ({type}));
`).toFail(
/Type '{ type: string; }' is not assignable to type '"type property is not allowed in action creators"'/
/Type '\(type: string\) => \{ type: string; \}' is not assignable to type '"type property is not allowed in action creators"'/
);
});

it('should not allow arrays', () => {
expectSnippet(`
const foo = createAction('FOO', () => [ ]);
`).toFail(
/Type 'any\[]' is not assignable to type '"arrays are not allowed in action creators"'/
/Type '\(\) => any\[\]' is not assignable to type '"arrays are not allowed in action creators"'/
);
});
});
Expand Down
1 change: 1 addition & 0 deletions modules/store/spec/types/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ export const compilerOptions = () => ({
moduleResolution: 'node',
target: 'es2015',
baseUrl: '.',
experimentalDecorators: true,
paths: {
'@ngrx/store': ['./modules/store'],
},
Expand Down
2 changes: 1 addition & 1 deletion modules/store/src/action_creator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export function createAction<T extends string>(
): ActionCreator<T, () => TypedAction<T>>;
export function createAction<T extends string, P extends object>(
type: T,
config: Props<P>
config: Props<P> & NotAllowedCheck<P>
): ActionCreator<T, (props: P & NotAllowedCheck<P>) => P & TypedAction<T>>;
export function createAction<
T extends string,
Expand Down

0 comments on commit f6336d5

Please sign in to comment.