Skip to content

Commit

Permalink
Remove DisallowArraysAndTypeProperty and create Props
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-okrushko committed Jan 7, 2020
1 parent ab5254a commit 7ed56c8
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
5 changes: 3 additions & 2 deletions modules/store/src/action_creator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
TypedAction,
FunctionWithParametersType,
NotAllowedCheck,
Props,
} from './models';

// Action creators taken from ts-action library and modified a bit to better
Expand All @@ -14,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: { _as: 'props'; _p: P }
config: Props<P>
): ActionCreator<T, (props: P & NotAllowedCheck<P>) => P & TypedAction<T>>;
export function createAction<
T extends string,
Expand Down Expand Up @@ -120,7 +121,7 @@ export function createAction<T extends string, C extends Creator>(
}
}

export function props<P extends object>(): { _as: 'props'; _p: P } {
export function props<P extends object>(): Props<P> {
return { _as: 'props', _p: undefined! };
}

Expand Down
9 changes: 5 additions & 4 deletions modules/store/src/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,6 @@ export const arraysAreNotAllowedMsg =
'arrays are not allowed in action creators';
type ArraysAreNotAllowed = typeof arraysAreNotAllowedMsg;

export type DisallowArraysAndTypeProperty<T> = T extends any[]
? ArraysAreNotAllowed
: T extends { type: any } ? TypePropertyIsNotAllowed : T;

export const typePropertyIsNotAllowedMsg =
'type property is not allowed in action creators';
type TypePropertyIsNotAllowed = typeof typePropertyIsNotAllowedMsg;
Expand Down Expand Up @@ -89,6 +85,11 @@ export type ActionCreator<
C extends Creator = Creator
> = C & TypedAction<T>;

export interface Props<T> {
_as: 'props';
_p: T;
}

export type FunctionWithParametersType<P extends unknown[], R = void> = (
...args: P
) => R;
Expand Down

0 comments on commit 7ed56c8

Please sign in to comment.