Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: typehinting react useForm with interface #2246

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

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
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.
1 participant