From c3eef69e2efb3b51e94f2e84ca6938ec5b1a3d9d Mon Sep 17 00:00:00 2001 From: Carson Full Date: Tue, 27 Dec 2016 17:12:06 -0600 Subject: [PATCH] Redux Form v6 (#13214) * [Redux Form] Rename current definitions to 4.0 * Added start of redux-form v6 definition * Defined arrayMove parameter types * Unexported action creators that are not exported * Form props/methods don't need to be optional * Updated decorator to infer the component generic type * Fix reducer definition. State should always be the FormStateMap type not a generic. Returned is the state AND object with plugin method (not or). * Removed namespace. I think this will make it easier to extend functionality....just follow redux's lead really. * Split meta, input, and custom props from RC4 change. Renamed MyFieldProps to FieldCustomProps to match documented wording. * Fix onDragStart, onDrop, onFocus * Update SubmitHandler doc to give more info and reference SubmissionError * Added Selectors * Replace Form's fieldList with registeredFields * Split FieldArray's meta props out from rc4 change * Add submitSucceeded prop and setSubmitSucceeded action (#1428) * Added parse() and format() to Field * Removed value type from onBlur and onChange parameter (40c0d7e) * Revert handleSubmit change so TS sees both definitions as methods. * Nothing to see here... * Added props parameter to config's validate * Added array functions to FormProps * Removed unexported action creators * Overloaded reduxForm() to make generics optional. * Refactor Generic* interfaces from Field and FieldArray. These will have the generics, and the classes will have those generics set to any :( * Added some tests for definition. * Added pure option to config * Split definition into multiple files * [tsconfig] no implicit returns or this. enabled strict null checks and decorators. * Fix event handlers needing a element generic with any for now. * Added Fields * Updated definition for all changes up to v6.1.1. * Missed errors prop on SubmissionError * Updated definition for all changes up to v6.2.1. * Added header * Added validate and warn props https://github.com/erikras/redux-form/pull/2245 * Added clearAsyncError https://github.com/erikras/redux-form/pull/2213 * Added FieldArray get & getAll https://github.com/erikras/redux-form/pull/2247 * Updated version to 6.3.1 * Added react reference dependency * Fix initialize action. Thanks @csillag * Changed Normalizer, Formatter, Parser, Validator to types and exported them * Added original author of v4 definitions --- redux-form/index.d.ts | 486 ++---------------------- redux-form/lib/Field.d.ts | 313 ++++++++++++++++ redux-form/lib/FieldArray.d.ts | 214 +++++++++++ redux-form/lib/Fields.d.ts | 112 ++++++ redux-form/lib/FormSection.d.ts | 17 + redux-form/lib/actions.d.ts | 144 ++++++++ redux-form/lib/reducer.d.ts | 49 +++ redux-form/lib/reduxForm.d.ts | 551 ++++++++++++++++++++++++++++ redux-form/lib/selectors.d.ts | 74 ++++ redux-form/redux-form-4.0-tests.tsx | 331 +++++++++++++++++ redux-form/redux-form-4.0.d.ts | 476 ++++++++++++++++++++++++ redux-form/redux-form-tests.tsx | 345 ++--------------- redux-form/tsconfig.json | 7 +- 13 files changed, 2343 insertions(+), 776 deletions(-) create mode 100644 redux-form/lib/Field.d.ts create mode 100644 redux-form/lib/FieldArray.d.ts create mode 100644 redux-form/lib/Fields.d.ts create mode 100644 redux-form/lib/FormSection.d.ts create mode 100644 redux-form/lib/actions.d.ts create mode 100644 redux-form/lib/reducer.d.ts create mode 100644 redux-form/lib/reduxForm.d.ts create mode 100644 redux-form/lib/selectors.d.ts create mode 100644 redux-form/redux-form-4.0-tests.tsx create mode 100644 redux-form/redux-form-4.0.d.ts diff --git a/redux-form/index.d.ts b/redux-form/index.d.ts index 77a3004710..4c73f3e489 100644 --- a/redux-form/index.d.ts +++ b/redux-form/index.d.ts @@ -1,476 +1,38 @@ -// Type definitions for redux-form v4.0.3 +// Type definitions for redux-form v6.3.1 // Project: https://github.com/erikras/redux-form -// Definitions by: Daniel Lytkin +// Definitions by: Carson Full , Daniel Lytkin // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -import * as React from 'react'; -import { Component, SyntheticEvent, FormEventHandler } from 'react'; -import { Dispatch, ActionCreator, Reducer } from 'redux'; +/// -export const actionTypes: {[actionName:string]: string}; +import { + ComponentClass, + StatelessComponent, +} from 'react'; export type FieldValue = any; -export type FormData = { [fieldName: string]: FieldValue }; +export type FieldType = 'Field' | 'FieldArray'; -export interface FieldProp { - /** - * true if this field currently has focus. It will only work if you are - * passing onFocus to your input element. - */ - active: boolean; +export type DataShape = {[fieldName:string]: FieldValue}; - /** - * An alias for value only when value is a boolean. Provided for - * convenience of destructuring the whole field object into the props of a - * form element. - */ - checked?: boolean; +export type FormErrors = FormData & { _error?: string }; - /** - * true if the field value has changed from its initialized value. - * Opposite of pristine. - */ - dirty: boolean; - - /** - * The error for this field if its value is not passing validation. Both - * synchronous and asynchronous validation errors will be reported here. - */ - error?: any; - - /** - * The value for this field as supplied in initialValues to the form. - */ - initialValue: FieldValue; - - /** - * true if the field value fails validation (has a validation error). - * Opposite of valid. - */ - invalid: boolean; - - /** - * The name of the field. It will be the same as the key in the fields - * Object, but useful if bundling up a field to send down to a specialized - * input component. - */ - name: string; - - /** - * A function to call when the form field loses focus. It expects to - * either receive the React SyntheticEvent or the current value of the - * field. - */ - onBlur(eventOrValue: SyntheticEvent | FieldValue): void; - - /** - * A function to call when the form field is changed. It expects to either - * receive the React SyntheticEvent or the new value of the field. - * @param eventOrValue - */ - onChange(eventOrValue: SyntheticEvent | FieldValue): void; - - /** - * A function to call when the form field receives a 'dragStart' event. - * Saves the field value in the event for giving the field it is dropped - * into. - */ - onDragStart(): void; - - /** - * A function to call when the form field receives a drop event. - */ - onDrop(): void; - - /** - * A function to call when the form field receives focus. - */ - onFocus(): void; - - /** - * An alias for onChange. Provided for convenience of destructuring the - * whole field object into the props of a form element. Added to provide - * out-of-the-box support for Belle components' onUpdate API. - */ - onUpdate(): void; - - /** - * true if the field value is the same as its initialized value. Opposite - * of dirty. - */ - pristine: boolean; - - /** - * true if the field has been touched. By default this will be set when - * the field is blurred. - */ - touched: boolean; - - /** - * true if the field value passes validation (has no validation errors). - * Opposite of invalid. - */ - valid: boolean; - - /** - * The value of this form field. It will be a boolean for checkboxes, and - * a string for all other input types. - */ - value: FieldValue; - - /** - * true if this field has ever had focus. It will only work if you are - * passing onFocus to your input element. - */ - visited: boolean; -} - -export interface ReduxFormProps { - /** - * The name of the currently active (with focus) field. - */ - active?: string; - - /** - * A function that may be called to initiate asynchronous validation if - * asynchronous validation is enabled. - */ - asyncValidate?: Function; - - /** - * true if the asynchronous validation function has been called but has not - * yet returned. - */ - asyncValidating?: boolean; - - /** - * Destroys the form state in the Redux store. By default, this will be - * called for you in componentWillUnmount(). - */ - destroyForm?(): void; - - /** - * true if the form data has changed from its initialized values. Opposite - * of pristine. - */ - dirty?: boolean; - - /** - * A generic error for the entire form given by the _error key in the - * result from the synchronous validation function, the asynchronous - * validation, or the rejected promise from onSubmit. - */ - error?: any; - - /** - * The form data, in the form { field1: , field2: }. The - * field objects are meant to be destructured into your input component as - * props, e.g. . Each field Object has - * the following properties: - */ - fields?: { [field: string]: FieldProp }; - - /** - * A function meant to be passed to
or to - *