-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
fix: Nested deep partial with unknown #11373
fix: Nested deep partial with unknown #11373
Conversation
Review or Edit in CodeSandboxOpen the branch in Web Editor • VS Code • Insiders |
Hi! I just found out about this PR. Sorry for the unintended bug in #11333. To reinstate the problem, my previous PR didn't make nested properties on objects no longer optional for all object types. I was unaware that a union type containing both objects and non-object primitives didn't pass the However your solution seems to effectively revert the definition of Before I upload a new PR, I'll post a new solution here to check for both cases:
This will be able to extract any object types that are present in a union(if T[K] happens to be one) and effectively apply If all looks good, I'll upload a new PR with some type tests to account for all these cases we have found. |
@RulerOfCakes please send a pr, would be good if we can include some type tests as well. 🙏 |
@RulerOfCakes Ah yes your solution is what I was aiming to do! I figured that |
…hook-form#11373) * fix: Nested deep partial with unknown * reset editor files * added api extractor
Hi!
In the recent
7.49.3
release, there was a change to make the DeepPartial compatible withunknown
..The side effect of this PR, however, was to make nested properties on objects no longer optional. I believe this is because the
DeepPartial
checked forextends object
which inherently excludes all other types likestring | null | undefined
. I am not a TS wizard, but I think I am close with that assumption.My change is to check for
T extends never
, which should solve this issue with unknown attempting to be solved in the previous PR but also preserving the types of non-object keysAn example of the issue I am referring to can be found here. The errors in questions will not appear on a version of this app with
react-hook-form
below7.49.3
. An example at7.49.2
without the bug can be found hereI want to reiterate I am not a TS wizard, and I very well could be wrong with this solution. However, I am pretty sure we could label the behavior introduced in
7.49.3
as a bug.