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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix typescript typings in FieldProps #619

Merged
merged 1 commit into from
Nov 7, 2019
Merged

Fix typescript typings in FieldProps #619

merged 1 commit into from
Nov 7, 2019

Conversation

bwlt
Copy link
Contributor

@bwlt bwlt commented Sep 10, 2019

According to the doc the parse prop takes the value from the input (which is typed with FieldValue)

According to [the doc](https://final-form.org/docs/react-final-form/types/FieldProps#parse) the parse prop takes the value from the input (which is typed with `FieldValue`)
@codecov
Copy link

codecov bot commented Sep 10, 2019

Codecov Report

Merging #619 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@          Coverage Diff          @@
##           master   #619   +/-   ##
=====================================
  Coverage     100%   100%           
=====================================
  Files          17     17           
  Lines         248    248           
  Branches       57     57           
=====================================
  Hits          248    248

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 3add0f3...d0d7604. Read the comment docs.

@erikras erikras merged commit 762b122 into final-form:master Nov 7, 2019
@erikras
Copy link
Member

erikras commented Nov 18, 2019

Published in v6.3.1.

@br0wn
Copy link

br0wn commented Nov 18, 2019

Hello. I ran into issue with this PR when I have different type of value in the input than that is stored in the form values. I get following error:

Type '(value: moment.Moment | undefined) => string | undefined' is not assignable to type '(value: Moment | undefined, name: string) => Moment | undefined'.
  Type 'string | undefined' is not assignable to type 'Moment | undefined'.
    Type 'string' is not assignable to type 'Moment | undefined'.
const parseDate = useCallback(
    (value: Moment | undefined) => value ? value.format('YYYY-MM-DD') : undefined,
    []
  );
interface FormValues {
  ...
  date?: string;
  ...
}
<Field
  name="date"
  allowNull={true}
  parse={parseDate}
  format={formatDate}
  render={render={({ input }) => (
    <DatePicker 
      value={input.value as any} 
      onChange={(value) => input.onChange({ target: { value } })}
    />
  )}
/>

My case converts Moment object to string, but it can be applied to the example from documentation as well:

parsing localized dates into actual javascript Date objects

Does the FieldValue typing represent the value of the field stored in the form or the value put into the input?

@Juansasa
Copy link

Juansasa commented Nov 19, 2019

This fix broke everything for us.

We do use custom input and the data types used for the input does not necessary mean the form type.

Format: formType => inputType
Parse: inputType =>formType not formtype => formType it defeat the purpose of parsing in the first place.

Please fix this ASAP

@erikras
Copy link
Member

erikras commented Nov 19, 2019

I agree, @Juansasa.

erikras added a commit that referenced this pull request Nov 19, 2019
erikras added a commit that referenced this pull request Nov 19, 2019
@erikras
Copy link
Member

erikras commented Nov 19, 2019

Reverted in v6.3.3.

@lock
Copy link

lock bot commented Dec 19, 2019

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators Dec 19, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants