Skip to content

Conversation

matthiasweiss
Copy link

@matthiasweiss matthiasweiss commented Feb 24, 2025

Hello! Really love all of the great work you are doing with Inertia, by far my favorite way to build web apps 🥳

A previous PR (#2060) introduced stricter typing for the useForm hook.

However, this unfortunately breaks typehinting the hook, since the hook now requires and index signature for the generic. This also causes in the new Laravel starter kit, see laravel/react-starter-kit#31 for more info.

This PR fixes this, and also closes #2188.

@@ -6,7 +6,7 @@ import useRemember from './useRemember'
type setDataByObject<TForm> = (data: TForm) => void
type setDataByMethod<TForm> = (data: (previousData: TForm) => TForm) => void
type setDataByKeyValuePair<TForm> = <K extends keyof TForm>(key: K, value: TForm[K]) => void
type FormDataType = Record<string, FormDataConvertible>
type FormDataType = Partial<Record<string, FormDataConvertible>>
Copy link
Author

@matthiasweiss matthiasweiss Feb 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you prefer, I think we could also go for this notation, I don't mind either one.

Suggested change
type FormDataType = Partial<Record<string, FormDataConvertible>>
type FormDataType = { [key:string]?: FormDataConvertible }

@matthiasweiss matthiasweiss changed the title fix: typehinting react useForm with interface (#2188) fix: typehinting react useForm with interface Feb 24, 2025
@JosephusPaye
Copy link

JosephusPaye commented Mar 13, 2025

Thanks for taking a stab at this @matthiasweiss. I just ran into this problem too.

Unfortunately, it doesn't seem to solve the problem. Here are some TypeScript playground links demonstrating this:

@joetannenbaum
Copy link
Contributor

Typehinting for useForm should be far more robust now that #2181 has been merged. If this is still an issue feel free to open a new PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[2.0.1] Typehinting useForm with interface gives error.
3 participants