Skip to content

Commit

Permalink
fix(store): replace Creator with ActionCreator on createAction (#2299)
Browse files Browse the repository at this point in the history
* fix(store): replace insufficient type Creator with TypedCreator

createAction returns incorrect type as neither Creator not it's return type contains `type`.
Proper return type is ActionCreator with inner typed creator

Closes meeroslav/ng-helpers#2

* fix(store): revert TypedCreator in favor of upcoming NotAllowedCheck
  • Loading branch information
meeroslav authored and alex-okrushko committed Jan 6, 2020
1 parent 98b74ad commit fe6bfa7
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions modules/store/src/action_creator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ export function createAction<
export function createAction<T extends string, C extends Creator>(
type: T,
config?: { _as: 'props' } | C
): Creator {
): ActionCreator<T> {
if (typeof config === 'function') {
return defineType(type, (...args: any[]) => ({
...config(...args),
Expand Down Expand Up @@ -133,7 +133,10 @@ export function union<
return undefined!;
}

function defineType(type: string, creator: Creator): Creator {
function defineType<T extends string>(
type: T,
creator: Creator
): ActionCreator<T> {
return Object.defineProperty(creator, 'type', {
value: type,
writable: false,
Expand Down

0 comments on commit fe6bfa7

Please sign in to comment.