You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
where personInfo is typed as const personInfo: [string, number]
The problem for this use case is the fact that I cannot access the members of personInfo by the fieldNames, unlike getValues()
which returns field values
type FieldValues = {
[x: string]: any;
}
so if I want to reconstruct the information I have to use array indexes, which feels weird
And that's because K in keyof TPath returns a number ( if you used getValues, you will know that you will get an intellisense for length of the array numbers ), and the implementation of getValues indeed returns on array.
/// line 842
fieldNames.map((name) => get(values, name))
Suggested solution
If the fieldNames you provider are in the form of an array, maybe do something like
fieldNames.reduce((prev, name, i ) => {
let val = get(values, name)
return { ...prev, [name] : val }
}, {})
Version Number
7.43.9
Codesandbox/Expo snack
https://codesandbox.io/s/blazing-violet-kyn8w7?file=/src/App.tsx
Steps to reproduce
I have set up a crude copy of what I have for one of my projects. The point being
and types are set up using zod
FormSections defines multiple sections of the same form. This is used for triggering different interactive animations based on specific progress.
Using getValues() using array as an input returns an array back of the values, this is anticipated behavior.
where personInfo is typed as
const personInfo: [string, number]
The problem for this use case is the fact that I cannot access the members of personInfo by the fieldNames, unlike
getValues()
which returns field values
so if I want to reconstruct the information I have to use array indexes, which feels weird
Upon further digging, I was a little confused why this doesn't seem to already work based on
And that's because
K in keyof TPath
returns a number ( if you used getValues, you will know that you will get an intellisense for length of the array numbers ), and the implementation of getValues indeed returns on array.Suggested solution
If the fieldNames you provider are in the form of an array, maybe do something like
And change the type to something like
So that you get type completion on getValues(array) and allow you to interact with return values more predictably
Links used
microsoft/TypeScript#20965
Code of Conduct
The text was updated successfully, but these errors were encountered: