diff --git a/types/redux-actions/index.d.ts b/types/redux-actions/index.d.ts index cc8e813e7c..45ecf21933 100644 --- a/types/redux-actions/index.d.ts +++ b/types/redux-actions/index.d.ts @@ -4,7 +4,6 @@ // Alex Gorbatchev , // Alec Hill // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -// TypeScript Version: 2.3 export as namespace ReduxActions; @@ -23,12 +22,12 @@ export interface ActionMeta extends Action { meta: Meta; } -export interface ReducerMap { - [actionType: string]: Reducer | ReducerNextThrow; +export interface ReducerMap { + [actionType: string]: Reducer | ReducerNextThrow; } -export interface ReducerMapMeta { - [actionType: string]: ReducerMeta | ReducerNextThrowMeta; +export interface ReducerMapMeta { + [actionType: string]: ReducerMeta | ReducerNextThrowMeta; } export interface ReducerNextThrow { @@ -41,28 +40,58 @@ export interface ReducerNextThrowMeta { throw?(state: State, action: ActionMeta): State; } -export type ActionFunctions = ActionFunctionAny>; +export type ActionFunctions = + ActionFunction0> | + ActionFunction1> | + ActionFunction2> | + ActionFunction3> | + ActionFunction4> | + ActionFunctionAny>; export type Reducer = (state: State, action: Action) => State; export type ReducerMeta = (state: State, action: ActionMeta) => State; /** argument inferring borrowed from lodash definitions */ -export type ActionFunction = (t1?: T1, t2?: T2, t3?: T3, t4?: T4) => R; +export type ActionFunction0 = () => R; +export type ActionFunction1 = (t1: T1) => R; +export type ActionFunction2 = (t1: T1, t2: T2) => R; +export type ActionFunction3 = (t1: T1, t2: T2, t3: T3) => R; +export type ActionFunction4 = (t1: T1, t2: T2, t3: T3, t4: T4) => R; export type ActionFunctionAny = (...args: any[]) => R; export function createAction( actionType: string -): ActionFunction>; +): ActionFunction0>; -export function createAction( +export function createAction( actionType: string, - payloadCreator: ActionFunction -): ActionFunction, Arg1, Arg2, Arg3, Arg4>; + payloadCreator: ActionFunction0 +): ActionFunction0>; + +export function createAction( + actionType: string, + payloadCreator: ActionFunction1 +): ActionFunction1>; + +export function createAction( + actionType: string, + payloadCreator: ActionFunction2 +): ActionFunction2>; + +export function createAction( + actionType: string, + payloadCreator: ActionFunction3 +): ActionFunction3>; + +export function createAction( + actionType: string, + payloadCreator: ActionFunction4 +): ActionFunction4>; export function createAction( actionType: string -): ActionFunction, Payload>; +): ActionFunction1>; export function createAction( actionType: string, @@ -70,11 +99,29 @@ export function createAction( metaCreator: ActionFunctionAny ): ActionFunctionAny>; +export function createAction( + actionType: string, + payloadCreator: ActionFunction1, + metaCreator: ActionFunction1 +): ActionFunction1>; + +export function createAction( + actionType: string, + payloadCreator: ActionFunction2, + metaCreator: ActionFunction2 +): ActionFunction2>; + +export function createAction( + actionType: string, + payloadCreator: ActionFunction3, + metaCreator: ActionFunction3 +): ActionFunction3>; + export function createAction( actionType: string, - payloadCreator: ActionFunction, - metaCreator: ActionFunction -): ActionFunction, Arg1, Arg2, Arg3, Arg4>; + payloadCreator: ActionFunction4, + metaCreator: ActionFunction4 +): ActionFunction4>; export function handleAction( actionType: string | ActionFunctions, @@ -88,19 +135,24 @@ export function handleAction( initialState: State ): Reducer; -export function handleActions( - reducerMap: ReducerMap, - initialState: State -): Reducer; +export function handleActions( + reducerMap: ReducerMap, + initialState: StateAndPayload +): Reducer; -export function handleActions( - reducerMap: ReducerMapMeta, +export function handleActions( + reducerMap: ReducerMap, initialState: State -): ReducerMeta; +): Reducer; + +export function handleActions( + reducerMap: ReducerMapMeta, + initialState: State +): ReducerMeta; export function combineActions(...actionTypes: Array | string>): string; -export interface ActionMap { +export interface ActionMap { [actionType: string]: ActionMap | ActionFunctionAny | @@ -109,15 +161,8 @@ export interface ActionMap { } export function createActions( - actionMap: ActionMap, + actionMap: ActionMap, ...identityActions: string[] ): { [actionName: string]: ActionFunctionAny> }; - -export function createActions( - actionMap: ActionMap, - ...identityActions: string[] -): { - [actionName: string]: ActionFunctionAny> -}; diff --git a/types/redux-actions/redux-actions-tests.ts b/types/redux-actions/redux-actions-tests.ts index e12efd461f..b7eeb2e62f 100644 --- a/types/redux-actions/redux-actions-tests.ts +++ b/types/redux-actions/redux-actions-tests.ts @@ -144,7 +144,7 @@ const typedActionHandlerWithMeta = ReduxActions.handleAction( +const typedActionHandlerReducerMetaMap = ReduxActions.handleActions( { INCREMENT_BY: { next(state: TypedState, action: ReduxActions.ActionMeta) {