Skip to content

Conversation

@michalwarda
Copy link

In TypeScript you can use generic syntax inside of JSX code to allow typing components.
react-final-form exposes a way to type Config FormData through createForm but there is no way to access it in react-final-form.

This pull request exposes the possibility to pass FormData typing to Form component.

I've also added typings tests for that.

@codecov
Copy link

codecov bot commented Feb 18, 2019

Codecov Report

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

Impacted file tree graph

@@          Coverage Diff          @@
##           master   #426   +/-   ##
=====================================
  Coverage     100%   100%           
=====================================
  Files          10     10           
  Lines         207    207           
  Branches       61     61           
=====================================
  Hits          207    207

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 768a476...657125c. Read the comment docs.

@erikras
Copy link
Member

erikras commented Feb 18, 2019

This pull request introduces 1 alert when merging 657125c into 768a476 - view on LGTM.com

new alerts:

  • 1 for Unused variable, import, function or class

Comment posted by LGTM.com

@wtgtybhertgeghgtwtg
Copy link
Contributor

values and initialValues will still be loosely typed. Should those get updated, as well?

@michalwarda
Copy link
Author

michalwarda commented Feb 22, 2019

@wtgtybhertgeghgtwtg I think that would require changing the type definitions inside final-form here, here and here.
I'll be glad to help with that but I'm not sure how to approach this multi-repo change.

@wtgtybhertgeghgtwtg
Copy link
Contributor

I'd guess make them generic with a default in a minor release for final-form, then bump the version in peerDependencies for the next react-final-form major.

@erikras
Copy link
Member

erikras commented Feb 25, 2019

@michalwarda I'd accept the PR for the FF changes, and then we can merge this RFF change, just like @wtgtybhertgeghgtwtg said.

@wtgtybhertgeghgtwtg I'm curious about the sentence that your username is abbreviating.

@wtgtybhertgeghgtwtg
Copy link
Contributor

It's not an abbreviation, I just mashed the keyboard.

@michalwarda
Copy link
Author

@erikras I'll do it in few hours :)

@whengely
Copy link

Are the changes going into FF the blocker currently for this or is it something else?

RenderableProps<FormRenderProps> {
subscription?: FormSubscription
decorators?: Decorator[]
initialValuesEqual?: (a?: object, b?: object) => boolean
Copy link

Choose a reason for hiding this comment

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

Shouldn't these also be FormData?


export var Field: React.ComponentType<FieldProps>
export var Form: React.ComponentType<FormProps>
export class Form<FormData = object> extends React.Component<
Copy link
Contributor

Choose a reason for hiding this comment

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

Form is actually implemented as a function, not as a class, so this type could be misleading couldn't it?

It would suggest I can create instances a la const form = new Form()?

Copy link

Choose a reason for hiding this comment

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

I've been doing this if it helps.

<FormData = object>(
  props: FormProps<FormData>,
) => React.ReactElement<FormProps<FormData>>

Copy link
Member

Choose a reason for hiding this comment

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

subscription?: FormSubscription
}

export var Field: React.ComponentType<FieldProps>
Copy link
Contributor

Choose a reason for hiding this comment

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

It would be nice for Field to get the same treatment.

@erikras
Copy link
Member

erikras commented May 27, 2019

Can you resubmit this PR (or resolve the conflicts)?

@erikras
Copy link
Member

erikras commented Jul 8, 2019

Thank you for this contribution! It provided guidance and impetus to getting this feature into the library.

I think #516 did what this PR did, so I think this one is obsolete now.

@erikras erikras closed this Jul 8, 2019
@lock
Copy link

lock bot commented Aug 7, 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 Aug 7, 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.

7 participants