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

Type return value of watch method when possible #590

Merged
merged 1 commit into from Nov 28, 2019
Merged

Type return value of watch method when possible #590

merged 1 commit into from Nov 28, 2019

Conversation

axelboc
Copy link
Contributor

@axelboc axelboc commented Nov 28, 2019

I was only able to type the return value for simple uses of the watch method - i.e. watch('myField'). It doesn't work with multiple fields or complex queries, like myArray[0] or myObject.nestedProp. If the field is not typed in the form's interface, the return value has type unknown, just as before.

const { watch } = useForm<{ myField: string }>();
const myFieldValue = watch('myField'); // <= type of `myFieldValue` inferred as `string`

Fixes #576

@axelboc axelboc changed the title Infer return type of watch method when possible Type return value of watch method when possible Nov 28, 2019
@codesandbox-ci
Copy link

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit c51440a:

Sandbox Source
react-hook-form-automation-server Configuration
relaxed-shamir-s6cp9 Issue #576

@bluebill1049
Copy link
Member

thank you very much @axelboc

@bluebill1049
Copy link
Member

merge when you ready :)

@axelboc
Copy link
Contributor Author

axelboc commented Nov 28, 2019

No worries! I don't have the rights to merge the PR, though, so I'll leave it to you 😉 Thanks!

@bluebill1049
Copy link
Member

Oops 😬

@bluebill1049 bluebill1049 merged commit 5614b44 into react-hook-form:master Nov 28, 2019
@axelboc axelboc deleted the watch-type-inferring branch November 29, 2019 14:11
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.

Return type of watch is unknown
2 participants