diff --git a/types/redux-actions/index.d.ts b/types/redux-actions/index.d.ts index d088592217..cc8e813e7c 100644 --- a/types/redux-actions/index.d.ts +++ b/types/redux-actions/index.d.ts @@ -4,6 +4,7 @@ // Alex Gorbatchev , // Alec Hill // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.3 export as namespace ReduxActions; @@ -22,12 +23,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 { @@ -40,58 +41,28 @@ export interface ReducerNextThrowMeta { throw?(state: State, action: ActionMeta): State; } -export type ActionFunctions = - ActionFunction0> | - ActionFunction1> | - ActionFunction2> | - ActionFunction3> | - ActionFunction4> | - ActionFunctionAny>; +export type ActionFunctions = 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 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 ActionFunction = (t1?: T1, t2?: T2, t3?: T3, t4?: T4) => R; export type ActionFunctionAny = (...args: any[]) => R; export function createAction( actionType: string -): ActionFunction0>; +): ActionFunction>; -export function createAction( +export function createAction( actionType: string, - 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>; + payloadCreator: ActionFunction +): ActionFunction, Arg1, Arg2, Arg3, Arg4>; export function createAction( actionType: string -): ActionFunction1>; +): ActionFunction, Payload>; export function createAction( actionType: string, @@ -99,29 +70,11 @@ 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: ActionFunction4, - metaCreator: ActionFunction4 -): ActionFunction4>; + payloadCreator: ActionFunction, + metaCreator: ActionFunction +): ActionFunction, Arg1, Arg2, Arg3, Arg4>; export function handleAction( actionType: string | ActionFunctions, @@ -135,34 +88,36 @@ export function handleAction( initialState: State ): Reducer; -export function handleActions( - reducerMap: ReducerMap, - initialState: StateAndPayload -): Reducer; - -export function handleActions( - reducerMap: ReducerMap, +export function handleActions( + reducerMap: ReducerMap, initialState: State -): Reducer; +): Reducer; -export function handleActions( - reducerMap: ReducerMapMeta, +export function handleActions( + reducerMap: ReducerMapMeta, initialState: State -): ReducerMeta; +): ReducerMeta; export function combineActions(...actionTypes: Array | string>): string; -export interface ActionMap { +export interface ActionMap { [actionType: string]: - ActionMap | - ActionFunctionAny | - [ActionFunctionAny, ActionFunctionAny] | - undefined; + ActionMap | + ActionFunctionAny | + [ActionFunctionAny, ActionFunctionAny] | + undefined; } +export function createActions( + actionMap: ActionMap, + ...identityActions: string[] +): { + [actionName: string]: ActionFunctionAny> +}; + export function createActions( actionMap: ActionMap, ...identityActions: string[] ): { - [actionName: string]: ActionFunctionAny> + [actionName: string]: ActionFunctionAny> }; diff --git a/types/redux-actions/redux-actions-tests.ts b/types/redux-actions/redux-actions-tests.ts index 003599c8bc..e12efd461f 100644 --- a/types/redux-actions/redux-actions-tests.ts +++ b/types/redux-actions/redux-actions-tests.ts @@ -1,4 +1,4 @@ -import * as ReduxActions from "redux-actions"; +import * as ReduxActions from 'redux-actions'; let state: number; const minimalAction: ReduxActions.BaseAction = { type: 'INCREMENT' }; @@ -33,14 +33,14 @@ const actionHandlerWithReduceMap = ReduxActions.handleAction( state = actionHandlerWithReduceMap(0, multiplyAction(10)); -const actionsHandler = ReduxActions.handleActions({ +const actionsHandler = ReduxActions.handleActions({ INCREMENT: (state: number, action: ReduxActions.Action) => state + action.payload, MULTIPLY: (state: number, action: ReduxActions.Action) => state * action.payload }, 0); state = actionsHandler(0, { type: 'INCREMENT' }); -const actionsHandlerWithInitialState = ReduxActions.handleActions({ +const actionsHandlerWithInitialState = ReduxActions.handleActions({ INCREMENT: { next: (state: number, action: ReduxActions.Action) => state + action.payload, }, @@ -112,9 +112,9 @@ ReduxActions.Action = ReduxActions.createAction( +const typedActionHandlerReducerMap = ReduxActions.handleActions( { - INCREMENT: (state: TypedState, action: ReduxActions.Action) => ({ value: state.value + 1 }) + INCREMENT: (state: TypedState, action: ReduxActions.Action) => ({ value: state.value + 1 }) }, {value: 1} ); @@ -144,7 +144,7 @@ const typedActionHandlerWithMeta = ReduxActions.handleAction( +const typedActionHandlerReducerMetaMap = ReduxActions.handleActions( { INCREMENT_BY: { next(state: TypedState, action: ReduxActions.ActionMeta) { @@ -159,7 +159,7 @@ const typedActionHandlerReducerMetaMap = ReduxActions.handleActions ReduxActions.ActionMeta = - ReduxActions.createAction( + ReduxActions.createAction( 'INCREMENT_BY', amount => ({ increase: amount }), amount => ({ remote: true }) @@ -172,7 +172,7 @@ actionMetaFrom1Arg.meta.remote; typedState = typedActionHandlerReducerMetaMap({ value: 0 }, actionMetaFrom1Arg); const typedActionWithMeta2TypedArgs: (value: number, remote: boolean) => ReduxActions.ActionMeta = - ReduxActions.createAction( + ReduxActions.createAction( 'INCREMENT_BY', (amount, remote) => ({ increase: amount }), (amount, remote) => ({ remote }) diff --git a/types/redux-promise/index.d.ts b/types/redux-promise/index.d.ts index 415709cd4e..5c0a5b3f50 100644 --- a/types/redux-promise/index.d.ts +++ b/types/redux-promise/index.d.ts @@ -2,6 +2,7 @@ // Project: https://github.com/acdlite/redux-promise // Definitions by: Rogelio Morrell Caballero , Kaur Kuut // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.3 import * as Redux from 'redux';