Skip to content

FormDataConvertible is forcing Record<string, ?> #2476

@HichemTab-tech

Description

@HichemTab-tech

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:

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    typescriptRelated to TypeScript implementation

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions