Skip to content

Conversation

BTiers
Copy link
Contributor

@BTiers BTiers commented Apr 29, 2021

Fix #4994

For reference, here is the sandbox that shows the issue

As explained in the issue mentioned above, this PR make use of TS variadic tuple types to extract the proper type of the tuple returned by watch & getValues

To avoid any potential breaking changes on watch type definition, I've kept the previously defined signatures.


The behaviour if this gets merged would be as follow

  • getValues:
type MyFormValues = {
    k1: string;
    ...,
    kN: number;
}

// Previously resolved to (string | ... | number)[]
const ['k1', ..., 'kN'] = getValues(['k1', ..., 'kN']);

// With this PR, resolved to [string, ..., number]
const ['k1', ..., 'kN'] = getValues(['k1', ..., 'kN']);
  • watch:
type MyFormValues = {
    k1: string;
    ...,
    k10: boolean,
    ...,
    kN: number;
}

// Previously resolved to (string | number | ...)[]
const [k1, ..., kN] = watch(['k1', ..., 'kN']);

// With this PR, all of the following calls resolved to [string, ..., number]
const [k1, ..., kN] = watch(['k1', ..., 'kN']);
const [k1, ..., kN] = watch<['k1', ..., 'kN']>(['k1', ..., 'kN']);

// To avoid any breaking changes, this call resolved to [string, ..., boolean] as prior to this PR
// The limit for this syntax still being at 10 keys
const [k1, ..., k10] = watch<'k1', ..., 'k10'>(['k1', ..., 'k10']);

Ps: First time contributing to an open source project, happy to take any advices :)

Copy link
Member

@kotarella1110 kotarella1110 left a comment

Choose a reason for hiding this comment

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

Awesome 🎉
Thank you 🙌

@bluebill1049
Copy link
Member

Thanks very much @BTiers for the PR and @kotarella1110's review.

@bluebill1049 bluebill1049 merged commit 426ea00 into react-hook-form:master Apr 30, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[v7] watch method return types when over 10 keys watched
3 participants