-
Notifications
You must be signed in to change notification settings - Fork 515
Description
Inertia adapter(s) affected
- React
- Vue 3
- Svelte
- Not Applicable
JS package version
2.0.17
Backend stack (optional)
No response
Describe the problem
The type FormDataConvertible
which is used in useForm
is forcing the type injected in useForm to have Record<string, ?>
, which will cause issues in case we want to use an array in the form body,
the source:
inertia/packages/core/src/types.ts
Lines 13 to 22 in 232e1a0
export type FormDataConvertible = | |
| Array<FormDataConvertible> | |
| { [key: string]: FormDataConvertible } | |
| Blob | |
| FormDataEntryValue | |
| Date | |
| boolean | |
| number | |
| null | |
| undefined |
Example:
interface SomeType {
id: string;
value: string;
}
interface MyBody {
field1: string:
//... other fields
fieldThatNeedsAnArray: SomeType[]
}
const form = useForm<MyBody>({
field1: "",
//... other fields
fieldThatNeedsAnArray: []
});
In this case we would have a typescript problem saying :
Type
SomeType
is not assignable to type{ [key: string]: FormDataConvertible; }
So is there a spesific raison why we are forcing the { [key: string]: FormDataConvertible; }
? because i went throught the code and i found that this is used heavily in other places and I didn't think it was safe to just open a PR and change this type, any thoughts ?
Steps to reproduce
already mentioned above.