🚏 feat: support optional array fields in PathValueImpl type#13057
Merged
bluebill1049 merged 5 commits intoreact-hook-form:masterfrom Sep 20, 2025
Conversation
bluebill1049
approved these changes
Sep 20, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When targeting an item of an optional array field, the
PathValueImpltype omits the fact that the array is optional.Given a type
MyType, with an optional string array as a field:PathValueImpl<MyType, `optionalArray.${number}`>should bestring | undefinedsinceoptionalArrayis possiblyundefined. Using the current version, the returned type would bestring.PathValueImpl<string[] | undefined,`${number}`>should bestring | undefined. Using the current version, the returned type would bestring.Given this, the following code should not get any Typescript errors:
Here is a typescript playground comparing the results using current and new version of
PathValueImpl.I encountered this while using
useWatchon my form containing an optional array field, noticing the returned type wasn't safe since it doesn't enforce handling the case where the result isundefined.This PR:
PathValueImpltype to take optional array fields into considerationPathValue, which usesPathValueImpl, to ensure the returned type extendsundefinedwhen targeting an optional array fieldContributingdocumentation by replacing thetsdtype tests command bytest:type, as I noticed the command wasn't right while following the contributing guide.By the way, I'm a developper using react-hook-form for professional purposes. I work at ChapsVision. I specifically created a professional GitHub account for this PR, that's why it is so young and empty.