Looking to develop a custom data type where InputKeys will serve as the keys, and the values will be key/value pairs. The keys should correspond to InputFieldKey, with the value being a string.
My current progress includes {[key: string]: string}
, but I need the key in this context to relate to the main key.
I've successfully established a parent-child relationship using <Record,
for the parent part. However, I am struggling with constructing the child part which necessitates another layer of parent/child connections.
There could be varying numbers of ???InputFieldKeys
, each containing multiple fields beyond just 3 like (firstName
, lastName
, ...
, ...
)
I am open to adjusting the code as needed to achieve the desired structure, and potentially utilizing generics if beneficial.
type InputKeys = 'user' | 'building'
type UserInputFieldKey = 'firstName' | 'lastName' | 'age'
type AddressInputFieldKey = 'line1' | 'line2' | 'zip'
type InputError = Record<InputKeys, {[key: string]: string}>
const errors: InputError = {
user: {
firstName: 'First name must be entered',
},
address: {},
}
Guidance on this matter would be greatly appreciated.