Open sgronblo opened 5 years ago
I have found FormikProps
to be similar, but Iād like a type here too for use in sub component props.
+1. Currently, if you want to use the return type of useFormik
in another function, you have to type it as ReturnType<typeof useFormik>
. However, useFormik
is a generic argument, but you cannot specify generic arguments when using typeof
. For example doing ReturnType<typeof useFormik<MyCustomFormValues>>
is a syntax error.) So any object you pass in there that specified generic fields will result in the following error:
Argument of type '{ initialValues: MyCustomFormValues, initial...
...
Type 'FormikValues' is not assignable to type 'MyCustomFormValues'
This makes wrapping useFormik
with a custom wrapper mentioned in #2339 challenging/tedious when it comes to type safety/correctness.
~EDIT: Looks like FormikConfig<Values>
might be :ok_hand:~
EDIT 2: Looks like FormikContextType<Values>
is better
Found a work around for this
export type Formik<T extends FormikValues> = ReturnType<typeof useFormik<T>>;
š Bug report
Current Behavior
The return type for
useFormik
is defined inline.Expected behavior
There should be a separate type defined for the return value of
useFormik
Reproducible example
N/A
Suggested solution(s)
Add an explicit return type for
useformik
at https://github.com/jaredpalmer/formik/blob/d90149e6e75aada13a2a02f390495d268237ce04/src/Formik.tsx#L135Additional context
Trying to add formik step by step to an application. Want to specify the type of a component property that matches whatever
useFormik
returns. Currently I have to specify my ownFormConfig
type and add whatever I need there.Your environment