Wrong TS typing of input.value when using parseValue/formatValue that convert types
See original GitHub issueAre 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 add parseValue
that gets string
from select and returns Date
to store, and I add formatValue
which does the opposite.
In this case I would expect the input.value
of FieldRenderProps
to be a string
but typescript infers its type as Date
(in fact it’s a string). So I see a TS error.
What is the expected behavior?
I would expect the input.value
of FieldRenderProps
to be a string
.
Sandbox Link
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.
Issue Analytics
- State:
- Created 2 years ago
- Reactions:2
- Comments:5 (1 by maintainers)
Top GitHub Comments
Published fix in
v6.5.4
.@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
Date
s but I need to submit date-only formatted strings to server. And I prefer submitting form state unchanged without running it through some pre-submit converter. This is the case where type conversion through parse/format could help.@mrfratello wow thanks! Your PR really fixes the thing for me 😍 Too bad it is unlikely to be merged. The repo looks abandoned.