Let’s say I have the following model definition:
export interface formData {
formSection: {},
errors: formError[]
}
export interface formError {
[key: string]: {
'default'?: string
'201'?: string
}
}
and I receive a JSON like this:
{
"formSection": {},
"errors": {
"firstName": {
"default": "invalid first name",
"201": "first name has invalid characters"
}
}
}
how can I access errors.firstName.default
when TS does not know about the firstName key existence? If I do something like:
const myFunction = (param: formData) => {
return (
<>
{param.errors.firstName.value}
</>
)
}
TS will complain saying firstName
does not exist in the model, which is correct, but then how can I access that “dynamic” key?