Help: Typescript errors support for field arrays
See original GitHub issueDescribe the bug I have a form in which I dynamically create field arrays (as in the examples). Therefore I have the following Typescript interface:
export interface ICostInformationFormValues {
rentalCost: number;
additionalCost: Array<{ name: string; value: number }>;
}
I want to display validation errors for the dynamically generated fields and that’s the problem. The field arrays are handled differently in the errors than in for example getValues({ nested: true }). Instead of using my Typescript interface, the Field Array error messages are stored with the index of the field name (e.g.: “additionalCost[1][value]”).
When I try to read the errors for this field:
errors["additionalCost[1][value]"]
I get the following Typescript error message:
Element implicitly has an 'any' type because expression of type '"additionalCost[1][value]"' can't be used to index type 'Partial<Record<"rentalCost" | "additionalCost", FieldError>>'.
Property 'additionalCost[1][value]' does not exist on type 'Partial<Record<"rentalCost" | "additionalCost", FieldError>>'.
When I simply log the errors value to my console I can see the error messages for the array fields. I just can’t read them with Typescript support.
Expected behavior I would expect to be able to read the error messages based on my Typescript interface like I read the errors for every other field.
errors.additionalCost[1]["value"].message
Additional context I’m using Material-UI to create my textfields. If you need more context please let me know.
Thanks for your help 😃 Daniel
Issue Analytics
- State:
- Created 4 years ago
- Comments:5 (4 by maintainers)

Top Related StackOverflow Question
@bluebill1049 We just need to union it with a string. Change
https://github.com/react-hook-form/react-hook-form/blob/75d213c4fb6e686aad6befab8d9d917cd25ffd62/src/types.ts#L100
to
Record<keyof Data | string, FieldError>@yeyep we going to release the patch soon