-
-
Notifications
You must be signed in to change notification settings - Fork 482
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
Wrong TS typing of input.value when using parseValue/formatValue that convert types #929
Comments
This is not a bug. You are explicitly setting the value of your |
@callmeberzerker As far as I understand the type parameter of the |
Yep I understand what you want, and while I agree it it would be super cool if it was possible -> I am not sure how Also some 2cents from my side in general regarding form handling - you should prefer to store The reason being let's take a I never use parse - but I do use format (which is handling a Field value of the same type)... and when I use |
@callmeberzerker I think that UX considerations stand apart from the issue I described. Yes, your example makes sense but I've had a couple of real life form fields that could win from such type conversion without harming the UX. For example I use a custom DatePicker component that accepts and returns @mrfratello wow thanks! Your PR really fixes the thing for me 😍 |
Published fix in |
Are you submitting a bug report or a feature request?
A bug report I think
What is the current behavior?
So if I make a simple field that stores values of type A and uses some input that accepts values of type B, I get a weird type mismatch.
For example, I have a field of type
Date
that uses a simple html select as input (please see a sandbox link below). I addparseValue
that getsstring
from select and returnsDate
to store, and I addformatValue
which does the opposite.In this case I would expect the
input.value
ofFieldRenderProps
to be astring
but typescript infers its type asDate
(in fact it's a string). So I see a TS error.What is the expected behavior?
I would expect the
input.value
ofFieldRenderProps
to be astring
.Sandbox Link
https://codesandbox.io/s/strongly-typed-form-values-with-react-final-form-forked-nfmmq?file=/src/index.tsx
What's your environment?
react-final-form: 6.3.5
final-form: 4.20.1
typescript: 4.3.2
Other information
Maybe I'm doing something wrong. Would appreciate if anyone could help me to figure the things out.
The text was updated successfully, but these errors were encountered: