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

[V2] handleChange should accept any value #2084

Open
blueberry6401 opened this issue Dec 5, 2019 · 4 comments
Open

[V2] handleChange should accept any value #2084

blueberry6401 opened this issue Dec 5, 2019 · 4 comments

Comments

@blueberry6401
Copy link

馃悰 Bug report

Current Behavior

I'm using Formik on React-native and Typescript.
For example, I have only one field of type number:

type MyFieldValues = {
  val: number,
}

On input handleChange
formikProps.handleChange('val')(newVal as number);

Got this: Error:(100, 46) TS2345: Argument of type 'number' is not assignable to parameter of type 'string | ChangeEvent'.

Expected behavior

handleChange should accept any value type like setFieldValue does.

Your environment

Software Version(s)
Formik 2.0.6
React 16.9.0
TypeScript 3.6.3
Browser
npm/Yarn
Operating System Mac 10.15.1
@elkinjosetm
Copy link

What's the update on this bug?

@stale stale bot added the stale label Mar 13, 2020
@blueberry6401
Copy link
Author

Shouldn't this be fixed? I still use patch-package to handle this tiny bug.

@johnrom
Copy link
Collaborator

johnrom commented Jan 25, 2021

I explain the resolution for this in depth here: #3013 (comment)

Unfortunately, we need to upgrade TS to TS4 to actually solve this problem, so this will probably be a major version update.

Edit: I do think we can accept any (or unknown and cast to any, so we can properly check for Events) in handleChange for now, but when we eventually add real typings that will be a breaking change. @jaredpalmer I think we can change this to any in v2, so the breaking change can occur in the jump from v2 to v3.

@johnrom johnrom removed the stale label Jan 25, 2021
@JulianKingman
Copy link

The problem is not only types and typescript, but also functionally it only accepts strings or events. The types are actually correct, in that if you pass anything else, you run into this error: #1667 (dupes: #2942, #1973).

Here are some closed PR's that try to address the above issue:
https://github.com/formium/formik/pull/2305/files
https://github.com/formium/formik/pull/1669/files (#2255 was supposed to carry this on, but looks like the type part didn't make it)
https://github.com/formium/formik/pull/3039/files

Based on @johnrom 's comment here, it seems that setFieldValue should be used instead of handleChange? If that's true, then perhaps we just need a documentation update for the migrating-v2 guide page.

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

No branches or pull requests

4 participants