-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Return Types for useFormik #2924
Comments
Agreed |
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 60 days |
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 60 days |
I'm also looking for this one |
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 60 days |
+1 want me to make a PR? Can you give me some advice? |
The types for Formik in v2 aren't set up to easily generate a complete return type. useFormik has a complete return type in my v3 branch. You can check it out here This consists of:
Which ultimately breaks down to type FormikApiAndConfig =
// API
FormikHelpers &
FormikHandlers &
FormikRegistration &
FormikFieldHelpers &
{ getValueFromEvent } &
// Config
FormikValidationConfig<Values> &
{ enableReinitialize: boolean } &
FormikState; // replaced with FormikStateHelpers in v3 Some of those types are newly created in my v3 branch so you'd have to dig deep to recreate them for v2. In v3 these types are spread across two contexts, FormikContext (FormikApi) and FormikConfigContext (FormikConfig). |
Making it: Base on your types:
|
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 60 days |
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 60 days |
@basile-savouret typeof automatically removes generics. These two are not the same:
One is |
It's true. It works out for me because i don't need the generics handle by formik. |
The generic helps to prevent "wild guesses" when it comes to Field names and such, especially in the typed v3.1 PR #3152 which you can test here: https://www.npmjs.com/package/@johnrom/formik-v3/v/3.1.0-types12 if you're not using completely dynamic data, I'd recommend trying it out as it can help discover bugs that haven't been discovered yet. I would locate type issues using that package and then push to production using the Formik production version you're already using. Both that PR and the v3.0 PR #3231 have a strongly typed return value already. |
We make use of useFormik to bind formik to another UI library, Everything works swimmingly. One issue though, is that there is no common return type for useFormik
It would be useful if there was a common interface for this value.
I believe it's equivalent to
FormikState<any> & FormikComputedProps<any> & FormikHelpers<any> & FormikHandlers
but I'm not sure.I propose adding the following to the types file if it's actually a complete representation of useFormik's output.
The text was updated successfully, but these errors were encountered: