From 6491acd2b294e5b0177daabac1d3263ed847372c Mon Sep 17 00:00:00 2001 From: Jared Palmer Date: Mon, 29 Jan 2018 14:00:30 -0500 Subject: [PATCH] Revert "Revert "Change layout of generics in main Formik class (#370)"" This reverts commit 6c51b7094b90f32c0e77e53921c44c64edba2011. --- src/formik.tsx | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/src/formik.tsx b/src/formik.tsx index 1aade45c2..db480981f 100644 --- a/src/formik.tsx +++ b/src/formik.tsx @@ -179,10 +179,10 @@ export type FormikProps = FormikState & FormikHandlers & FormikComputedProps; -export class Formik< - Props extends FormikConfig = FormikConfig, - Values = object -> extends React.Component> { +export class Formik extends React.Component< + FormikConfig & ExtraProps, + FormikState +> { static defaultProps = { validateOnChange: true, validateOnBlur: true, @@ -221,7 +221,7 @@ export class Formik< ? this.state.errors && Object.keys(this.state.errors).length === 0 : this.props.isInitialValid !== false && isFunction(this.props.isInitialValid) - ? (this.props.isInitialValid as (props: Props) => boolean)( + ? (this.props.isInitialValid as (props: this['props']) => boolean)( this.props ) : (this.props.isInitialValid as boolean), @@ -245,7 +245,7 @@ export class Formik< }; } - constructor(props: Props) { + constructor(props: FormikConfig & ExtraProps) { super(props); this.state = { values: props.initialValues || ({} as any), @@ -257,7 +257,9 @@ export class Formik< this.initialValues = props.initialValues || ({} as any); } - componentWillReceiveProps(nextProps: Props) { + componentWillReceiveProps( + nextProps: Readonly & ExtraProps> + ) { // If the initialValues change, reset the form if ( this.props.enableReinitialize && @@ -579,7 +581,7 @@ export class Formik< isValid: dirty ? this.state.errors && Object.keys(this.state.errors).length === 0 : isInitialValid !== false && isFunction(isInitialValid) - ? (isInitialValid as (props: Props) => boolean)(this.props) + ? (isInitialValid as (props: this['props']) => boolean)(this.props) : (isInitialValid as boolean), handleBlur: this.handleBlur, handleChange: this.handleChange, @@ -622,15 +624,11 @@ function warnAboutMissingIdentifier({ handlerName: string; }) { console.error( - `Warning: \`${ - handlerName - }\` has triggered and you forgot to pass an \`id\` or \`name\` attribute to your input: + `Warning: \`${handlerName}\` has triggered and you forgot to pass an \`id\` or \`name\` attribute to your input: ${htmlContent} - Formik cannot determine which value to update. For more info see https://github.com/jaredpalmer/formik#${ - documentationAnchorLink - } + Formik cannot determine which value to update. For more info see https://github.com/jaredpalmer/formik#${documentationAnchorLink} ` ); }