// Type definitions for redux-saga-routines 3.1 // Project: https://github.com/afitiskin/redux-saga-routines // Definitions by: Alexey Pelykh // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 3.0 import { Dispatch } from 'redux'; import { Action, ActionMeta, createAction, ActionFunction0, ActionFunction1, ActionFunction2, ActionFunction3, ActionFunction4, ActionFunctionAny, } from 'redux-actions'; import { FormSubmitHandler } from 'redux-form'; import { string } from 'prop-types'; export function routinePromiseWatcherSaga(): IterableIterator; export type RoutineStages = 'TRIGGER' | 'REQUEST' | 'SUCCESS' | 'FAILURE' | 'FULFILL'; export type ActionCreatorFunction = ActionFunctionAny< Action | ActionMeta >; export type Routine< TTriggerActionCreator = ActionCreatorFunction, TRequestActionCreator = ActionCreatorFunction, TSuccessActionCreator = ActionCreatorFunction, TFailureActionCreator = ActionCreatorFunction, TFulfillActionCreator = ActionCreatorFunction > = TTriggerActionCreator & { [key in RoutineStages]: string; } & { trigger: TTriggerActionCreator; request: TRequestActionCreator; success: TSuccessActionCreator; failure: TFailureActionCreator; fulfill: TFulfillActionCreator; }; export type UnifiedRoutine = Routine< TActionCreator, TActionCreator, TActionCreator, TActionCreator, TActionCreator >; export type ResolveFunctionReturnType = TFunction extends (...args: any[]) => infer TReturn ? TReturn : undefined; export type ResolveFunctionArg1Type = TFunction extends (arg1: infer TArg1, ...args: any[]) => any ? TArg1 : undefined; export type ResolveFunctionArg2Type = TFunction extends (arg1: any, arg2: infer TArg1, ...args: any[]) => any ? TArg1 : undefined; export type ResolveFunctionArg3Type = TFunction extends (arg1: any, arg2: any, arg3: infer TArg1, ...args: any[]) => any ? TArg1 : undefined; export type ResolveFunctionArg4Type = TFunction extends (arg1: any, arg2: any, arg3: any, arg4: infer TArg1, ...args: any[]) => any ? TArg1 : undefined; export type ResolveActionCreatorByPayload< TPayloadCreator, TPayload = ResolveFunctionReturnType, TArg1 = ResolveFunctionArg1Type, TArg2 = ResolveFunctionArg2Type, TArg3 = ResolveFunctionArg3Type, TArg4 = ResolveFunctionArg4Type > = TPayloadCreator extends ActionFunction0 ? ActionFunction0> : TPayloadCreator extends ActionFunction1 ? ActionFunction1> : TPayloadCreator extends ActionFunction2 ? ActionFunction2> : TPayloadCreator extends ActionFunction3 ? ActionFunction3> : TPayloadCreator extends ActionFunction4 ? ActionFunction4> : ActionFunctionAny>; export type ResolveActionCreatorByMeta< TMetaCreator, TMeta = ResolveFunctionReturnType, TArg1 = ResolveFunctionArg1Type, TArg2 = ResolveFunctionArg2Type, TArg3 = ResolveFunctionArg3Type, TArg4 = ResolveFunctionArg4Type > = TMetaCreator extends ActionFunction0 ? ActionFunction0> : TMetaCreator extends ActionFunction1 ? ActionFunction1> : TMetaCreator extends ActionFunction2 ? ActionFunction2> : TMetaCreator extends ActionFunction3 ? ActionFunction3> : TMetaCreator extends ActionFunction4 ? ActionFunction4> : ActionFunctionAny>; export type ResolveActionCreatorByPayloadMeta< TPayloadCreator, TMetaCreator, TPayload = ResolveFunctionReturnType, TMeta = ResolveFunctionReturnType, TArg1 = ResolveFunctionArg1Type, TArg2 = ResolveFunctionArg2Type, TArg3 = ResolveFunctionArg3Type, TArg4 = ResolveFunctionArg4Type > = TMetaCreator extends ActionFunction0 ? ActionFunction0> : TMetaCreator extends ActionFunction1 ? ActionFunction1> : TMetaCreator extends ActionFunction2 ? ActionFunction2> : TMetaCreator extends ActionFunction3 ? ActionFunction3> : TMetaCreator extends ActionFunction4 ? ActionFunction4> : ActionFunctionAny>; export interface ReduxFormPayload { values: TFormData; props: TProps; } export function bindRoutineToReduxForm< TFormData = {}, TProps = {}, >( routine: Routine< ActionFunction1, Action>> > | Routine< ActionFunction1, ActionMeta, any>> >, noSuccessPayload?: boolean, ): FormSubmitHandler; export type PromiseCreator< TPayload = {}, > = (payload: TPayload, dispatch: Dispatch) => PromiseLike; export function promisifyRoutine( routine: Routine, ): PromiseCreator; export type BoundPromiseCreator< TPayload = {}, > = (payload: TPayload) => PromiseLike; export function bindPromiseCreators( promiseCreator: PromiseCreator, dispatch: Dispatch, ): BoundPromiseCreator; export function bindPromiseCreators( promiseCreators: { [key: string]: PromiseCreator }, dispatch: Dispatch, ): { [key: string]: BoundPromiseCreator }; export function bindPromiseCreators( promiseCreators: { [key: number]: PromiseCreator }, dispatch: Dispatch, ): { [key: number]: BoundPromiseCreator }; export const ROUTINE_PROMISE_ACTION: string; // NOTE: Default payloadCreator is identity (x => x) // NOTE: Same payloadCreator is used for all actions of the routine export function createRoutine< Payload = any >( typePrefix: string ): UnifiedRoutine< (payload?: Payload) => Action >; // NOTE: Same payloadCreator is used for all actions of the routine export function createRoutine< Payload >( typePrefix: string, payloadCreator: ActionFunction0 ): UnifiedRoutine< ActionFunction0> >; // NOTE: Same payloadCreator is used for all actions of the routine export function createRoutine< Payload, Arg1 >( typePrefix: string, payloadCreator: ActionFunction1, ): UnifiedRoutine< ActionFunction1> >; // NOTE: Same payloadCreator is used for all actions of the routine export function createRoutine< Payload, Arg1, Arg2 >( typePrefix: string, payloadCreator: ActionFunction2, ): UnifiedRoutine< ActionFunction2> >; // NOTE: Same payloadCreator is used for all actions of the routine export function createRoutine< Payload, Arg1, Arg2, Arg3 >( typePrefix: string, payloadCreator: ActionFunction3, ): UnifiedRoutine< ActionFunction3> >; // NOTE: Same payloadCreator is used for all actions of the routine export function createRoutine< Payload, Arg1, Arg2, Arg3, Arg4 >( typePrefix: string, payloadCreator: ActionFunction4, ): UnifiedRoutine< ActionFunction4> >; // NOTE: Default payloadCreator is identity (x => x) // NOTE: Same payloadCreator is used for all actions of the routine export function createRoutine< Meta >( typePrefix: string, payloadCreator: null | undefined, metaCreator: ActionFunctionAny, ): UnifiedRoutine< (payload?: any) => ActionMeta >; // NOTE: Same payloadCreator is used for all actions of the routine export function createRoutine< Payload, Meta >( typePrefix: string, payloadCreator: ActionFunctionAny, metaCreator: ActionFunctionAny, ): UnifiedRoutine< ActionFunctionAny> >; // NOTE: Same payloadCreator is used for all actions of the routine export function createRoutine< Payload, Meta, Arg1 >( typePrefix: string, payloadCreator: ActionFunction1, metaCreator: ActionFunction1, ): UnifiedRoutine< ActionFunction1> >; // NOTE: Same payloadCreator is used for all actions of the routine export function createRoutine< Payload, Meta, Arg1, Arg2 >( typePrefix: string, payloadCreator: ActionFunction2, metaCreator: ActionFunction2, ): UnifiedRoutine< ActionFunction2> >; // NOTE: Same payloadCreator is used for all actions of the routine export function createRoutine< Payload, Meta, Arg1, Arg2, Arg3 >( typePrefix: string, payloadCreator: ActionFunction3, metaCreator: ActionFunction3, ): UnifiedRoutine< ActionFunction3> >; // NOTE: Same payloadCreator is used for all actions of the routine export function createRoutine< Payload, Meta, Arg1, Arg2, Arg3, Arg4 >( typePrefix: string, payloadCreator: ActionFunction4, metaCreator: ActionFunction4, ): UnifiedRoutine< ActionFunction4> >; export function createRoutine< TTriggerPayloadCreator, TRequestPayloadCreator, TSuccessPayloadCreator, TFailurePayloadCreator, TFulfillPayloadCreator >( typePrefix: string, payloadCreator: { TRIGGER?: TTriggerPayloadCreator, trigger?: TTriggerPayloadCreator, REQUEST?: TRequestPayloadCreator, request?: TRequestPayloadCreator, SUCCESS?: TSuccessPayloadCreator, success?: TSuccessPayloadCreator, FAILURE?: TFailurePayloadCreator, failure?: TFailurePayloadCreator, FULFILL?: TFulfillPayloadCreator, fulfill?: TFulfillPayloadCreator } ): Routine< ResolveActionCreatorByPayload, ResolveActionCreatorByPayload, ResolveActionCreatorByPayload, ResolveActionCreatorByPayload, ResolveActionCreatorByPayload >; export function createRoutine< TTriggerMetaCreator, TRequestMetaCreator, TSuccessMetaCreator, TFailureMetaCreator, TFulfillMetaCreator >( typePrefix: string, payloadCreator: null | undefined, metaCreator: { TRIGGER?: TTriggerMetaCreator, trigger?: TTriggerMetaCreator, REQUEST?: TRequestMetaCreator, request?: TRequestMetaCreator, SUCCESS?: TSuccessMetaCreator, success?: TSuccessMetaCreator, FAILURE?: TFailureMetaCreator, failure?: TFailureMetaCreator, FULFILL?: TFulfillMetaCreator, fulfill?: TFulfillMetaCreator } ): Routine< ResolveActionCreatorByMeta, ResolveActionCreatorByMeta, ResolveActionCreatorByMeta, ResolveActionCreatorByMeta, ResolveActionCreatorByMeta >; export function createRoutine< TTriggerPayloadCreator, TRequestPayloadCreator, TSuccessPayloadCreator, TFailurePayloadCreator, TFulfillPayloadCreator, TTriggerMetaCreator, TRequestMetaCreator, TSuccessMetaCreator, TFailureMetaCreator, TFulfillMetaCreator >( typePrefix: string, payloadCreator: { TRIGGER?: TTriggerPayloadCreator, trigger?: TTriggerPayloadCreator, REQUEST?: TRequestPayloadCreator, request?: TRequestPayloadCreator, SUCCESS?: TSuccessPayloadCreator, success?: TSuccessPayloadCreator, FAILURE?: TFailurePayloadCreator, failure?: TFailurePayloadCreator, FULFILL?: TFulfillPayloadCreator, fulfill?: TFulfillPayloadCreator }, metaCreator: { TRIGGER?: TTriggerMetaCreator, trigger?: TTriggerMetaCreator, REQUEST?: TRequestMetaCreator, request?: TRequestMetaCreator, SUCCESS?: TSuccessMetaCreator, success?: TSuccessMetaCreator, FAILURE?: TFailureMetaCreator, failure?: TFailureMetaCreator, FULFILL?: TFulfillMetaCreator, fulfill?: TFulfillMetaCreator } ): Routine< ResolveActionCreatorByPayloadMeta, ResolveActionCreatorByPayloadMeta, ResolveActionCreatorByPayloadMeta, ResolveActionCreatorByPayloadMeta, ResolveActionCreatorByPayloadMeta >;