-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
feat(useForm): improve type parameter specification to useForm #6568
base: next
Are you sure you want to change the base?
feat(useForm): improve type parameter specification to useForm #6568
Conversation
🦋 Changeset detectedLatest commit: d0ce6ee The changes in this PR will be included in the next version bump. This PR includes changesets to release 2 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
✅ Deploy Preview for refine-doc-live-previews ready!Built without sensitive environment variables
To edit notification comments on pull requests, go to your Netlify site configuration. |
const FormVariablesSymbol = Symbol("FormVariables"); | ||
const SubmissionVariablesSymbol = Symbol("SubmissionVariables"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need these?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
here we use Symbol
for FormVariables
and SubmissionVariables
to ensure uniqueness and avoid conflicting with the basic TVariables shape. as Ali mentioned here .
PR Checklist
Please check if your PR fulfills the following requirements:
Bugs / Features
What is the current behavior?
The
useForm
hook uses a single type parameter for both the form structure and the data submitted to the API. This causes type conflicts when trying to map form data into the structure needed for the API . As a result, developers encounter type errors when attempting to submit transformed data.What is the new behavior?
After the changes, the
useForm
hook introduces an additional type parameter for submission data . This separates the form structure type from the submission type .onFinish
function correctly expects the SubmissionData type instead of the form structure type. allowing developers to easily map and submit the data without running into type issues.fixes #6137
Notes for reviewers
The
onValid
function is wrapped inonValidWrapper
to address a TypeScript error where the form data (TVariables
) does not match the expected structure foronValid
. This results in a type conflict, so use type casting (variables as unknown as ExtractFormVariables<TVariables>
) to ensure the correct form data type is passed toonValid
. This resolves the error and ensures type safety during form submission.