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

issue: useWatch returntype is not partial when getting specific fields. #9954

Closed
1 task done
martin-wahlberg opened this issue Feb 17, 2023 · 4 comments
Closed
1 task done
Labels
question Further information is requested TS Typescript related issues

Comments

@martin-wahlberg
Copy link

martin-wahlberg commented Feb 17, 2023

Version Number

7.43.1

Codesandbox/Expo snack

https://codesandbox.io/s/react-typescript-forked-rlj5bx?file=/src/App.tsx

Steps to reproduce

  1. Goto the code sandbox.
  2. See the error

Expected behaviour

Typescript should tell me that the fields are possibly undefined.

I guess i am expecting something like

}): DeepPartialSkipArrayKey<FieldPathValue<TFieldValues, TFieldName>> | undefined;

here:
https://github.com/react-hook-form/react-hook-form/blob/master/src/useWatch.ts#L77
and here
https://github.com/react-hook-form/react-hook-form/blob/master/src/useWatch.ts#L110

What browsers are you seeing the problem on?

No response

Relevant log output

No response

Code of Conduct

  • I agree to follow this project's Code of Conduct
@martin-wahlberg martin-wahlberg changed the title issue: useWatch returntype is not partial when getting single fields. issue: useWatch returntype is not partial when getting specific fields. Feb 17, 2023
@bluebill1049
Copy link
Member

We are moving away from DeepPartial in the next major, this is something that gives us so many issues as such. I would recommend you provide the correct type for your form values.

@bluebill1049 bluebill1049 added question Further information is requested TS Typescript related issues labels Feb 17, 2023
@martin-wahlberg
Copy link
Author

What do you mean by providing correct types? Isn't it correct that form-elements could have a undefined value until they are set?

@bluebill1049
Copy link
Member

Isn't it correct that form-elements could have a undefined value until they are set?

Your data type should be partial in the first place, we are moving away DeepPartail in the next major version, and async defaultValues is already not supported by deep partial.

@martin-wahlberg
Copy link
Author

martin-wahlberg commented Feb 17, 2023

Yeah ok then i understand what you mean :) Sounds nice that you are moving away from DeepPartial in v8. Thanks for the help.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 18, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
question Further information is requested TS Typescript related issues
Projects
None yet
Development

No branches or pull requests

2 participants