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: watch() does not return the same type passed to useForm #11480

Closed
1 task done
FredrikMWold opened this issue Feb 5, 2024 · 6 comments
Closed
1 task done

issue: watch() does not return the same type passed to useForm #11480

FredrikMWold opened this issue Feb 5, 2024 · 6 comments
Labels
regression Regression with code change

Comments

@FredrikMWold
Copy link

FredrikMWold commented Feb 5, 2024

Version Number

7.50.0

Codesandbox/Expo snack

https://codesandbox.io/p/devbox/frosty-monad-gk8xw3?layout=%257B%2522sidebarPanel%2522%253A%2522EXPLORER%2522%252C%2522rootPanelGroup%2522%253A%257B%2522direction%2522%253A%2522horizontal%2522%252C%2522contentType%2522%253A%2522UNKNOWN%2522%252C%2522type%2522%253A%2522PANEL_GROUP%2522%252C%2522id%2522%253A%2522ROOT_LAYOUT%2522%252C%2522panels%2522%253A%255B%257B%2522type%2522%253A%2522PANEL_GROUP%2522%252C%2522contentType%2522%253A%2522UNKNOWN%2522%252C%2522direction%2522%253A%2522vertical%2522%252C%2522id%2522%253A%2522cls8rzys400062v6kw1bmtxh5%2522%252C%2522sizes%2522%253A%255B70%252C30%255D%252C%2522panels%2522%253A%255B%257B%2522type%2522%253A%2522PANEL_GROUP%2522%252C%2522contentType%2522%253A%2522EDITOR%2522%252C%2522direction%2522%253A%2522horizontal%2522%252C%2522id%2522%253A%2522EDITOR%2522%252C%2522panels%2522%253A%255B%257B%2522type%2522%253A%2522PANEL%2522%252C%2522contentType%2522%253A%2522EDITOR%2522%252C%2522id%2522%253A%2522cls8rzys400022v6koztwxu09%2522%257D%255D%257D%252C%257B%2522type%2522%253A%2522PANEL_GROUP%2522%252C%2522contentType%2522%253A%2522SHELLS%2522%252C%2522direction%2522%253A%2522horizontal%2522%252C%2522id%2522%253A%2522SHELLS%2522%252C%2522panels%2522%253A%255B%257B%2522type%2522%253A%2522PANEL%2522%252C%2522contentType%2522%253A%2522SHELLS%2522%252C%2522id%2522%253A%2522cls8rzys400032v6kwgz856tn%2522%257D%255D%252C%2522sizes%2522%253A%255B100%255D%257D%255D%257D%252C%257B%2522type%2522%253A%2522PANEL_GROUP%2522%252C%2522contentType%2522%253A%2522DEVTOOLS%2522%252C%2522direction%2522%253A%2522vertical%2522%252C%2522id%2522%253A%2522DEVTOOLS%2522%252C%2522panels%2522%253A%255B%257B%2522type%2522%253A%2522PANEL%2522%252C%2522contentType%2522%253A%2522DEVTOOLS%2522%252C%2522id%2522%253A%2522cls8rzys400052v6k8al13bw8%2522%257D%255D%252C%2522sizes%2522%253A%255B100%255D%257D%255D%252C%2522sizes%2522%253A%255B50%252C50%255D%257D%252C%2522tabbedPanels%2522%253A%257B%2522cls8rzys400022v6koztwxu09%2522%253A%257B%2522id%2522%253A%2522cls8rzys400022v6koztwxu09%2522%252C%2522activeTabId%2522%253A%2522cls8v4z6v00cs2v6k8jfje1jh%2522%252C%2522tabs%2522%253A%255B%257B%2522id%2522%253A%2522cls8rzys400012v6k1xke0lmj%2522%252C%2522mode%2522%253A%2522permanent%2522%252C%2522type%2522%253A%2522FILE%2522%252C%2522filepath%2522%253A%2522%252Fpublic%252Findex.html%2522%252C%2522state%2522%253A%2522IDLE%2522%257D%252C%257B%2522type%2522%253A%2522FILE%2522%252C%2522filepath%2522%253A%2522%252F.codesandbox%252Ftasks.json%2522%252C%2522id%2522%253A%2522cls8v4z6v00cs2v6k8jfje1jh%2522%252C%2522mode%2522%253A%2522permanent%2522%257D%255D%257D%252C%2522cls8rzys400052v6k8al13bw8%2522%253A%257B%2522id%2522%253A%2522cls8rzys400052v6k8al13bw8%2522%252C%2522activeTabId%2522%253A%2522cls8usqmt001a2v6kqff13d4r%2522%252C%2522tabs%2522%253A%255B%257B%2522type%2522%253A%2522TASK_PORT%2522%252C%2522taskId%2522%253A%2522dev%2522%252C%2522port%2522%253A5173%252C%2522id%2522%253A%2522cls8usqmt001a2v6kqff13d4r%2522%252C%2522mode%2522%253A%2522permanent%2522%252C%2522path%2522%253A%2522%252F%2522%257D%255D%257D%252C%2522cls8rzys400032v6kwgz856tn%2522%253A%257B%2522id%2522%253A%2522cls8rzys400032v6kwgz856tn%2522%252C%2522activeTabId%2522%253A%2522cls8v1w8j005h2v6k65lk1c13%2522%252C%2522tabs%2522%253A%255B%257B%2522id%2522%253A%2522cls8v1w8j005h2v6k65lk1c13%2522%252C%2522mode%2522%253A%2522permanent%2522%252C%2522type%2522%253A%2522TERMINAL%2522%252C%2522shellId%2522%253A%2522cls8v1wal000odigm0ons3moc%2522%257D%255D%257D%257D%252C%2522showDevtools%2522%253Atrue%252C%2522showShells%2522%253Atrue%252C%2522showSidebar%2522%253Atrue%252C%2522sidebarPanelSize%2522%253A15%257D

Steps to reproduce

  1. Hover over allFields variable
  2. Hover over singleField variable

The isssue is present on v7.50.0 and on v7.49.3

Expected behaviour

When calling watch() with out any parameters the type of all fields get set to "optional".
If you pass a parameter to watch() then the correct type gets returned.

Expect the typing og watch() without any paramater to return the same type as the generic passed to useForm()

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

Related #11359

@calderwoodra
Copy link

+1 - also seeing this issue. Reverting back to 7.49.3 fixes it.

@bluebill1049
Copy link
Member

is this a regression?

@bluebill1049 bluebill1049 added the regression Regression with code change label Feb 6, 2024
@Isola92
Copy link

Isola92 commented Feb 6, 2024

This caused errors in about 10 files in our project. Most of these were caused by us calling watch without arguments and then destructuring the returned object. Like:

const {someProp} = watch()

And these errors are easily fixed by specifying the prop:
const someProp = watch("someProp")

Which I assume is better anyway so I didn't mind fixing those.

We did however have a couple of places where we want to watch the entire form and then I had to cast the return value of watch:

const { watch } = useFormContext<SomeModel>(); const programData = watch() as SomeModel

This seems unnecessary.

@bluebill1049
Copy link
Member

looks like a regression. I Will revert that commit. Thanks for the update.

@bluebill1049
Copy link
Member

reverted and publishing now.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 6, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
regression Regression with code change
Projects
None yet
Development

No branches or pull requests

5 participants