I'm trying to use yup with typescript and react-hook-form, basically the ts compiler doesn't let me map over the forminputs which are inferred from yup schema. Here's is the code. Accessing data[key] shows the error.
const addAccountSchema = yup.object({
accountName: yup.string().required("Name is required"),
userName: yup.string().required("User name is required")
...
...
file: yup.mixed().required("Image is required"),
});
type AddAccountInputs = yup.InferType<typeof addAccountSchema>;
const onSubmit = handleSubmit(async (data) => {
const formData = new FormData();
Object.keys(data).forEach((key) => {
if (key === "file") {
formData.append(key, data[key][0]);
} else {
formData.append(key, data[key]);
}
}); ```
```ts
{/ *
Element implicitly has an 'any' type because expression of type 'string' can't be used to index type 'AssertsShape<{ accountName: RequiredStringSchema<string | undefined, AnyObject>; userName: RequiredStringSchema<string | undefined, AnyObject>; ... 6 more ...; insightImage: MixedSchema<...>; }>'.
No index signature with a parameter of type 'string' was found on type 'AssertsShape<{ accountName: RequiredStringSchema<string | undefined, AnyObject>; userName: RequiredStringSchema<string | undefined, AnyObject>; ... 6 more ...; insightImage: MixedSchema<...>; }>'.ts(7053)
* /} ```