-
-
Notifications
You must be signed in to change notification settings - Fork 953
fix(Form): fix onChange type allowing strictly typed setState #4280
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
base: main
Are you sure you want to change the base?
fix(Form): fix onChange type allowing strictly typed setState #4280
Conversation
Review or Edit in CodeSandboxOpen the branch in Web Editor • VS Code • Insiders |
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. |
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.
Pull Request Overview
This pull request updates the Form component’s onChange prop type to support strictly typed state setters. The changes include:
- Updating the onChange prop signature in Form.tsx to use a new generic type M instead of V.
- Adding a test in FormSpec.tsx that demonstrates using a strictly typed setState function as the onChange callback.
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
File | Description |
---|---|
src/Form/Form.tsx | Updated the onChange prop signature to use generic type M for better TypeScript compatibility. |
src/Form/test/FormSpec.tsx | Added a test case verifying that a strictly typed setState can be passed to onChange without TypeScript errors. |
Comments suppressed due to low confidence (1)
src/Form/Form.tsx:102
- [nitpick] Consider renaming the generic parameter 'M' to a more descriptive name (e.g. 'FormValue') to improve clarity for API consumers.
onChange?: (formValue: M, event?: React.SyntheticEvent) => void;
@@ -99,7 +99,7 @@ export interface FormProps<V = Record<string, any>, M = any, E = { [P in keyof V | |||
/** | |||
* Callback fired when data changing | |||
*/ | |||
onChange?: (formValue: V, event?: React.SyntheticEvent) => void; | |||
onChange?: (formValue: M, event?: React.SyntheticEvent) => void; |
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.
FormProps<V = Record<string, any>, M = any, E = { [P in keyof V]?: M }>
Hi @nandobutzke, for FormProps, V, M, and E respectively represent Value, Message, and Error.
This PR updates the onChange prop type in the Form component by replacing the previous V = Record<string, any> constraint with a more flexible generic type M.
The goal is to allow the use of strongly-typed state management functions (e.g., setState from useState) without triggering TypeScript type errors.
Under the previous typing, TypeScript raised an error when attempting to pass a setState function directly to onChange with a strictly typed formValue, like:
Related issue: #4154