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 with control sets Typescript property types as nested Partial #9400

Closed
1 task done
Kersheh opened this issue Nov 19, 2022 · 1 comment
Closed
1 task done
Labels
question Further information is requested TS Typescript related issues

Comments

@Kersheh
Copy link

Kersheh commented Nov 19, 2022

Version Number

7.39.4

Codesandbox/Expo snack

https://codesandbox.io/s/usewatch-typescript-type-error-qjcmqo?file=/src/App.tsx:1065-1101

Steps to reproduce

  1. Configure useForm with generic form type defining concrete form value types (i.e. form values are not undefined)
  2. Use useWatch with control provided by return of useForm
  3. See values of useWatch appear as a nested Partial type (see line 51 of Codesandbox example)

Expected behaviour

Typescript form type defined as such with configured useForm and useWatch

interface FormValues {
  array: Array<{
    name: string;
  }>;
}

...

const { control } = useForm<FormValues>({ defaultValues: { array: [] } });
const { array } = useWatch({ control });

// type should be `Array<{ name: string }>` and not `Array<{ name?: string }> | undefined`
array.length; // Incorrectly displays --> Object is possibly 'undefined'.

and IDE should properly represent type as non-nested Partial when utilizing useWatch.

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
@bluebill1049
Copy link
Member

At the moment defaultValues itself is deep partial because it's possible to supply the entire form defaultValues or even don't supply at all, however, this is something we may change in the next major version, which could force the user to supply a none deep partial defaultValues, but this will be ba a breaking change for the better.

@bluebill1049 bluebill1049 closed this as not planned Won't fix, can't repro, duplicate, stale Nov 19, 2022
@bluebill1049 bluebill1049 added TS Typescript related issues question Further information is requested labels Nov 19, 2022
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 19, 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