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

Added tsx generic typings for Field, Form, and FormSpy components #522

Merged
merged 3 commits into from
Jun 14, 2019

Conversation

ChadLefort
Copy link
Contributor

As mentioned in #516 (comment), this should now allow for TSX generics for Field, Form, and FormSpy. This should allow you to pass in a type to either of these components, or in the case of the Form component if you pass in a typed initialValues prop typescript will infer the type.

For example:

const initialValues: { firstName: string } = { firstName: 'chad' };

<Form initialValues={initialValues} onSubmit={onSubmit}>
  {({ values, form }) => (
    // values and form api get the proper types
  )}
</Form>

@erikras
Copy link
Member

erikras commented Jun 11, 2019

This pull request introduces 1 alert when merging 58fb5f9 into 3dc413a - view on LGTM.com

new alerts:

  • 1 for Unused variable, import, function or class

This project has automated code review enabled, but doesn't use the LGTM GitHub App. Migrate over by installing the app. Read about the benefits of migrating to GitHub Apps in the blog.


Comment posted by LGTM.com

@codecov
Copy link

codecov bot commented Jun 11, 2019

Codecov Report

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

Impacted file tree graph

@@          Coverage Diff          @@
##           master   #522   +/-   ##
=====================================
  Coverage     100%   100%           
=====================================
  Files          15     16    +1     
  Lines         224    232    +8     
  Branches       55     57    +2     
=====================================
+ Hits          224    232    +8
Impacted Files Coverage Δ
src/FormSpy.js 100% <0%> (ø) ⬆️
src/useForm.js 100% <0%> (ø) ⬆️
src/ReactFinalForm.js 100% <0%> (ø) ⬆️
src/getContext.js 100% <0%> (ø)

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 02bf898...730d7aa. Read the comment docs.

isEqual?: (a: any, b: any) => boolean;
multiple?: boolean;
parse?: (value: any, name: string) => any;
parse?: (value: FieldValue, name: string) => FieldValue;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This value parameter should still be any, I think, as it's what is returned from the input. i.e. say we had a field of type number, but we had it in an <input type="text"/>, the whole point of the parse function is to do that conversion. I don't think it's a common enough use case to provide an UnparsedValue generic type.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea, that's true. Should have though about it a little bit more before I switched that. I'll switch it back to any.

@erikras
Copy link
Member

erikras commented Jun 11, 2019

This is AWESOME.

@ChadLefort
Copy link
Contributor Author

Updates for FieldArray also:
final-form/react-final-form-arrays#88

@erikras
Copy link
Member

erikras commented Jun 11, 2019

This pull request introduces 1 alert when merging db845a0 into 3dc413a - view on LGTM.com

new alerts:

  • 1 for Unused variable, import, function or class

This project has automated code review enabled, but doesn't use the LGTM GitHub App. Migrate over by installing the app. Read about the benefits of migrating to GitHub Apps in the blog.


Comment posted by LGTM.com

@erikras
Copy link
Member

erikras commented Jun 11, 2019

Chad! My man!! 👍

@erikras erikras merged commit 66a6c3e into final-form:master Jun 14, 2019
@erikras
Copy link
Member

erikras commented Jun 14, 2019

This pull request introduces 1 alert when merging 730d7aa into 02bf898 - view on LGTM.com

new alerts:

  • 1 for Unused variable, import, function or class

This project has automated code review enabled, but doesn't use the LGTM GitHub App. Migrate over by installing the app. Read about the benefits of migrating to GitHub Apps in the blog.


Comment posted by LGTM.com

@erikras
Copy link
Member

erikras commented Jun 14, 2019

Published in v6.2.0.

@lock
Copy link

lock bot commented Jul 14, 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 Jul 14, 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

2 participants