import { Component, ComponentType, Context, SyntheticEvent } from "react"; import { Dispatch } from "redux"; import { FieldType, FormErrors, FormStateMap, FormWarnings, RegisteredFieldState } from "../index"; import { Validator } from "./Field"; import { FormState } from "./reducer"; export type FormSubmitHandler = ( values: FormData, dispatch: Dispatch, props: DecoratedFormProps, // eslint-disable-next-line @typescript-eslint/no-invalid-void-type ) => void | FormErrors | Promise; export type GetFormState = (state: any) => FormStateMap; export interface SubmitHandler { ( submit: FormSubmitHandler, props?: DecoratedFormProps, valid?: boolean, asyncValidate?: any, fields?: string[], ): any; (event: SyntheticEvent): void; } export interface ValidateCallback { values: FormData; nextProps: DecoratedFormProps; props: DecoratedFormProps; initialRender: boolean; lastFieldValidatorKeys: string[]; fieldValidatorKeys: string[]; structure: any; } export interface AsyncValidateCallback { asyncErrors?: FormErrors | undefined; initialized: boolean; trigger: "blur" | "submit"; blurredField?: string | undefined; pristine: boolean; syncValidationPasses: boolean; } export interface InjectedArrayProps { insert(field: string, index: number, value: any): void; move(field: string, from: number, to: number): void; pop(field: string): void; push(field: string, value: any): void; remove(field: string, index: number): void; removeAll(field: string): void; shift(field: string): void; splice(field: string, index: number, removeNum: number, value: any): void; swap(field: string, indexA: number, indexB: number): void; unshift(field: string, value: any): void; } export interface RegisteredField { count: number; name: string; type: "Field" | "FieldArray"; } export interface InjectedFormProps { anyTouched: boolean; array: InjectedArrayProps; asyncValidate(): void; asyncValidating: string | boolean; autofill(field: string, value: any): void; blur(field: string, value: any): void; change(field: string, value: any): void; clearAsyncError(field: string): void; clearSubmit(): void; destroy(): void; dirty: boolean; error: ErrorType; form: string; handleSubmit: SubmitHandler; initialize(data: Partial): void; initialized: boolean; initialValues: Partial; invalid: boolean; pristine: boolean; reset(): void; submitFailed: boolean; submitSucceeded: boolean; submitting: boolean; touch(...field: string[]): void; untouch(...field: string[]): void; valid: boolean; warning: any; } export interface ConfigProps { form: string; asyncBlurFields?: string[] | undefined; asyncChangeFields?: string[] | undefined; asyncValidate?( values: FormData, dispatch: Dispatch, props: DecoratedFormProps, blurredField: string, ): Promise; destroyOnUnmount?: boolean | undefined; enableReinitialize?: boolean | undefined; forceUnregisterOnUnmount?: boolean | undefined; getFormState?: GetFormState | undefined; immutableProps?: string[] | undefined; initialValues?: Partial | undefined; keepDirtyOnReinitialize?: boolean | undefined; updateUnregisteredFields?: boolean | undefined; keepValues?: boolean | undefined; onChange?( values: Partial, dispatch: Dispatch, props: DecoratedFormProps, previousValues: Partial, ): void; onSubmit?: FormSubmitHandler | SubmitHandler | undefined; onSubmitFail?( errors: FormErrors | undefined, dispatch: Dispatch, submitError: any, props: DecoratedFormProps, ): void; onSubmitSuccess?(result: any, dispatch: Dispatch, props: DecoratedFormProps): void; propNamespace?: string | undefined; pure?: boolean | undefined; shouldValidate?(params: ValidateCallback): boolean; shouldError?(params: ValidateCallback): boolean; shouldWarn?(params: ValidateCallback): boolean; shouldAsyncValidate?(params: AsyncValidateCallback): boolean; submitAsSideEffect?: boolean | undefined; touchOnBlur?: boolean | undefined; touchOnChange?: boolean | undefined; persistentSubmitErrors?: boolean | undefined; validate?(values: FormData, props: DecoratedFormProps): FormErrors; warn?(values: FormData, props: DecoratedFormProps): FormWarnings; } export interface FormContext { form: string; getFormState: GetFormState; asyncValidate: { (name?: string, value?: any, trigger?: "blur" | "change"): Promise; }; getValues: { (): any }; sectionPrefix?: string | undefined; prefixName?: string | undefined; register: ( name: string, type: string, getValidator?: () => Validator | Validator[], getWarner?: () => Validator | Validator[], ) => void; unregister: (name: string) => void; registerInnerOnSubmit: (innerOnSubmit: () => void) => void; focus: (name: string) => void; change: (name: string, value: any) => void; blur: (name: string, value: any) => void; } export interface WrappedReduxFormContext { _reduxForm: FormContext; } export declare const ReduxFormContext: Context; export interface FormInstance extends Component

{ dirty: boolean; invalid: boolean; pristine: boolean; registeredFields: RegisteredFieldState[]; reset(): void; resetSection(...sections: string[]): void; submit(): Promise; valid: boolean; values: Partial; wrappedInstance?: HTMLElement | undefined; } export type SubmitAction = () => void; export type InitializeAction = ( initialValues: Partial, keepDirty: boolean, otherMeta?: any, ) => void; export type AutoFillAction = (field: string, value: any) => void; export type BlurAction = (field: string, value: any) => void; export type ChangeAction = (field: string, value: any) => void; export type FocusAction = (field: string) => void; export type ArrayUnshiftAction = (field: string, value: any) => void; export type ArrayShiftAction = (field: string) => void; export type ArraySpliceAction = ( field: string, index: number, removeNum: number, value: any, ) => void; export type ArrayInsertAction = (field: string, index: number, value: any) => void; export type ArrayMoveAction = (field: string, from: number, to: number) => void; export type ArrayPopAction = (field: string) => void; export type ArrayPushAction = (field: string, value: any) => void; export type ArrayRemoveAction = (field: string, index: number) => void; export type ArrayRemoveAllAction = (field: string) => void; export type ArraySwapAction = (field: string, indexA: number, indexB: number) => void; export type ClearSubmitAction = () => void; export type ClearSubmitErrorsAction = () => void; export type ClearAsyncErrorAction = (field: string) => void; export type ClearFieldsAction = (keepTouched: boolean, persistentSubmitErrors: boolean, ...fields: string[]) => void; export type DestroyAction = () => void; export type RegisterFieldAction = (name: string, type: FieldType) => void; export type UnregisterFieldAction = (name: string, destroyOnUnmount?: boolean) => void; export type ResetAction = () => void; export type ResetSectionAction = () => void; export type SetSubmitFailedAction = (...fields: string[]) => void; export type SetSubmitSucceededAction = (...fields: string[]) => void; export type StartAsyncValidationAction = (field: string) => void; export type StopAsyncValidationAction = (errors?: FormErrors) => void; export type StopSubmitAction = (errors?: FormErrors) => void; export type StartSubmitAction = () => void; export type TouchAction = (...fields: string[]) => void; export type UntouchAction = (...fields: string[]) => void; export type UpdateSyncErrorsAction = (syncErrors?: FormErrors, error?: any) => void; export type UpdateSyncWarningsAction = (syncErrors?: FormErrors, error?: any) => void; export type DecoratedFormState = FormState & { asyncErrors?: FormErrors | undefined; asyncValidating: boolean; dirty: boolean; error?: any; initialized: boolean; invalid: boolean; pristine: boolean; submitSucceeded: boolean; syncErrors?: FormErrors | undefined; syncWarnings?: FormWarnings | undefined; triggerSubmit?: boolean | undefined; valid: boolean; validExceptSubmit: boolean; warning?: any; }; export interface DecoratedFormActions { arrayInsert: ArrayInsertAction; arrayMove: ArrayMoveAction; arrayPop: ArrayPopAction; arrayPush: ArrayPushAction; arrayRemove: ArrayRemoveAction; arrayRemoveAll: ArrayRemoveAllAction; arrayShift: ArrayShiftAction; arraySplice: ArraySpliceAction; arraySwap: ArraySwapAction; arrayUnshift: ArrayUnshiftAction; autofill: AutoFillAction; clearSubmit: ClearSubmitAction; clearSubmitErrors: ClearSubmitErrorsAction; clearAsyncError: ClearAsyncErrorAction; clearFields: ClearFieldsAction; destroy: DestroyAction; initialize: InitializeAction; registerField: RegisterFieldAction; reset: ResetAction; resetSection: ResetSectionAction; startAsyncValidation: StartAsyncValidationAction; startSubmit: StartSubmitAction; stopAsyncValidation: StopAsyncValidationAction; stopSubmit: StopSubmitAction; submit: SubmitAction; setSubmitFailed: SetSubmitFailedAction; setSubmitSucceeded: SetSubmitSucceededAction; touch: TouchAction; unregisterField: UnregisterFieldAction; untouch: UntouchAction; updateSyncErrors: UpdateSyncErrorsAction; updateSyncWarnings: UpdateSyncWarningsAction; blur: BlurAction; change: ChangeAction; focus: FocusAction; array: InjectedArrayProps; dispatch: Dispatch; } export type DecoratedFormProps = & P & Partial> & Partial> & Partial> & { _reduxForm?: WrappedReduxFormContext | undefined }; export interface DecoratedComponentClass { new(props?: P, context?: any): FormInstance; } export type FormDecorator = ( component: ComponentType

>, ) => DecoratedComponentClass>; export declare function reduxForm( config: | ConfigProps | Partial>, ): FormDecorator; export default reduxForm;