diff --git a/src/buildActions/index.js b/src/buildActions/index.ts similarity index 60% rename from src/buildActions/index.js rename to src/buildActions/index.ts index c3b4848..0feaa10 100644 --- a/src/buildActions/index.js +++ b/src/buildActions/index.ts @@ -1,8 +1,14 @@ import fp from 'lodash/fp'; +import { Action } from '../types'; -function actionFor(type) { - const creator = ( (payload = undefined, meta = undefined) => - fp.pickBy(v => v !== undefined)({type, payload, meta}) +interface ActionCreator { + ( ...args: any[] ): Action; + _genericAction?: boolean +} + +function actionFor(type:string) { + const creator : ActionCreator = ( (payload = undefined, meta = undefined) => + fp.pickBy(v => v !== undefined)({type, payload, meta}) as Action ); creator._genericAction = true; @@ -11,7 +17,7 @@ function actionFor(type) { } export default function buildActions( - creators = {}, + creators : { [action: string]: Function } = {}, mutations = {}, effects = {}, subActions = [], @@ -31,7 +37,7 @@ export default function buildActions( ...generic, ...crafted, ...Object.entries(creators).map( - ([type, payload]) => [type, (...args) => ({ type, payload: payload(...args) })] + ([type, payload]: [ string, Function ]) => [type, (...args: any) => ({ type, payload: payload(...args) })] ), ]; diff --git a/src/buildUpreducer/index.ts b/src/buildUpreducer/index.ts index bedc8b2..5209d76 100644 --- a/src/buildUpreducer/index.ts +++ b/src/buildUpreducer/index.ts @@ -1,9 +1,9 @@ import fp from 'lodash/fp'; -import { Dictionary, Mutation, UpduxAction } from '../types'; +import { Dictionary, Mutation, Action } from '../types'; function buildUpreducer(initial: S, mutations: Dictionary> ) { - return (action :UpduxAction) => (state: S) => { + return (action :Action) => (state: S) => { if (state === null) state = initial; const a = diff --git a/src/types.ts b/src/types.ts index afdf4d1..0aa5fe9 100644 --- a/src/types.ts +++ b/src/types.ts @@ -1,9 +1,9 @@ -import { Action } from 'redux'; -export type UpduxAction = Action & Partial<{ - payload: any, - meta: any, -}> +export type Action = { + type: string, + payload?: any, + meta?: any, +} export type Dictionary = { [key: string]: T };