Skip to content

feat(useForm): export granular setData types and introduce SetDataAction<TForm> #2356

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

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

Conversation

hasib-devs
Copy link

Summary

This PR adds exportable type definitions for the different setData function signatures used in the useForm hook:

  • SetDataByObject<TForm>
  • SetDataByMethod<TForm>
  • SetDataByKeyValuePair<TForm>
  • SetDataAction<TForm> (union of the three above)

It also updates the InertiaFormProps<TForm> interface to use the new SetDataAction<TForm> type.

Motivation

When using useForm, developers often need to pass the setData method as a prop or context value. However, the composite type of setData was not previously exported, making it difficult to provide proper type annotations. Exporting these types improves type safety and developer experience in TypeScript-heavy applications.

What’s Changed

  • Introduced SetDataByObject, SetDataByMethod, SetDataByKeyValuePair types
  • Introduced SetDataAction<TForm> as a union of the above
  • Updated InertiaFormProps<TForm> to use SetDataAction<TForm>
  • Exported all new types

Notes

  • No breaking changes introduced
  • Existing usage of useForm remains intact
  • Only adds improved type safety and exports

…n for useForm

This commit introduces and exports the following new types to improve type inference and reusability for the useForm hook:

- SetDataByObject<TForm>
- SetDataByMethod<TForm>
- SetDataByKeyValuePair<TForm>
- SetDataAction<TForm> (a union of the above three)

These types are especially useful when passing setData as a prop or context value, enabling consumers to type it properly.

Also updated InertiaFormProps<TForm> to use the new SetDataAction<TForm> type.

This enhances developer experience when working with useForm in TypeScript-heavy applications.
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.

1 participant