Skip to content

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

Merged
erikras merged 3 commits into
final-form:masterfrom
ChadLefort:tsx-generics
Jun 14, 2019
Merged

Added tsx generic typings for Field, Form, and FormSpy components#522
erikras merged 3 commits into
final-form:masterfrom
ChadLefort:tsx-generics

Conversation

@ChadLefort

Copy link
Copy Markdown
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

erikras commented Jun 11, 2019

Copy link
Copy Markdown
Member

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

codecov Bot commented Jun 11, 2019

Copy link
Copy Markdown

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.

Comment thread typescript/index.d.ts Outdated
isEqual?: (a: any, b: any) => boolean;
multiple?: boolean;
parse?: (value: any, name: string) => any;
parse?: (value: FieldValue, name: string) => FieldValue;

Copy link
Copy Markdown
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
Copy Markdown
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

erikras commented Jun 11, 2019

Copy link
Copy Markdown
Member

This is AWESOME.

@ChadLefort

Copy link
Copy Markdown
Contributor Author

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

@erikras

erikras commented Jun 11, 2019

Copy link
Copy Markdown
Member

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

erikras commented Jun 11, 2019

Copy link
Copy Markdown
Member

Chad! My man!! 👍

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

erikras commented Jun 14, 2019

Copy link
Copy Markdown
Member

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 erikras mentioned this pull request Jun 14, 2019
@erikras

erikras commented Jun 14, 2019

Copy link
Copy Markdown
Member

Published in v6.2.0.

@lock

lock Bot commented Jul 14, 2019

Copy link
Copy Markdown

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.

2 participants