Skip to content
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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

No return type for useFormik function #2023

Open
sgronblo opened this issue Nov 13, 2019 · 4 comments
Open

No return type for useFormik function #2023

sgronblo opened this issue Nov 13, 2019 · 4 comments
Labels

Comments

@sgronblo
Copy link
Contributor

馃悰 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

}: FormikConfig<Values>) {

Additional 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 own FormConfig type and add whatever I need there.

Your environment

Software Version(s)
Formik formik@2.0.3
React react@16.9.0
TypeScript typescript@3.5.3
Browser Chrome Version 78.0.3904.87
npm/Yarn yarn 1.19.1
Operating System MacOS Mojave 1.14.6
@WestonThayer
Copy link

I have found FormikProps to be similar, but I鈥檇 like a type here too for use in sub component props.

@wbobeirne
Copy link

+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'

@stale stale bot added the stale label Feb 9, 2020
@davidroeca
Copy link

davidroeca commented Mar 9, 2020

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 馃憣
EDIT 2: Looks like FormikContextType<Values> is better

@stuart-clark-45
Copy link

stuart-clark-45 commented Dec 6, 2022

Found a work around for this

export type Formik<T extends FormikValues> = ReturnType<typeof useFormik<T>>;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants