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 useFormState and useField Flow types #630

Merged
merged 2 commits into from
Nov 7, 2019
Merged

Fix useFormState and useField Flow types #630

merged 2 commits into from
Nov 7, 2019

Conversation

redbmk
Copy link
Contributor

@redbmk redbmk commented Sep 18, 2019

The exported flow typing in index.js.flow doesn't match what's actually used in useFormState. When using this externally, this causes Flow to think that useFormState might return null or undefined, when that appears not to be the case. It also thinks that the params are required when they're really optional.

src/index.js.flow

declare export function useFormState<FormValues>(
  params: UseFormStateParams<FormValues>
): ?FormState<FormValues>

src/useFormState.js

function useFormState<FormValues: FormValuesShape>({
  onChange,
  subscription = all
}: UseFormStateParams<FormValues> = {}): FormState<FormValues> {

It looks like a similar change was made in #486 to fix the TypeScript typings in the same way.

typescript/index.d.ts

export function useField<T extends HTMLElement>(
   config: UseFieldConfig
 ): FieldRenderProps<T>;
 export function useForm(): FormApi;
-export function useFormState(params: UseFormStateParams): FormState | void;
+export function useFormState(params?: UseFormStateParams): FormState;
 export const version: string;

I'm using this locally with npm link and it's working for me. I would add // @flow to useFormState.test.js and then import from ./index instead of ./useFormState, but it seems flow and jest aren't working together out of the box.

@codecov
Copy link

codecov bot commented Sep 18, 2019

Codecov Report

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

Impacted file tree graph

@@          Coverage Diff          @@
##           master   #630   +/-   ##
=====================================
  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...d4d703f. Read the comment docs.

@redbmk redbmk changed the title Fix useFormState Flow types Fix useFormState and useField Flow types Sep 18, 2019
@redbmk
Copy link
Contributor Author

redbmk commented Sep 18, 2019

@erikras I also found that there were issues with the useField typings and figured out how to get flow working with jest, so now the tests have flow coverage as well. Since most people will be importing from index, I also changed the tests to import from index, which will pull in the exported flow typings.

@erikras erikras merged commit 3634b35 into final-form:master Nov 7, 2019
@redbmk redbmk deleted the useFormState-flow-typings branch November 7, 2019 16:15
@erikras
Copy link
Member

erikras commented Nov 18, 2019

Published in v6.3.1.

@lock
Copy link

lock bot commented Dec 18, 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 18, 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