-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Make Form generic for better TS support #5867
Conversation
✅ Deploy Preview for redwoodjs-docs canceled.
|
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.
I did a double take when I saw <Form<FormData>
, but it's a thing: https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-9.html#generic-type-arguments-in-jsx-elements.
I confirmed that it works as advertised! I understand your concern about type casting, but I don't understand quite enough about forwardRef
to comment on the tradeoff. (I did read the issue linked in the comments, but still.) I think I did try to implement this before back when I typed this file, but didn't know how to pass a generic to a JSX element. Now I do, so LGTM!
…ctmode-gen * 'main' of github.com:redwoodjs/redwood: (22 commits) Remove "node:os" import from telemetry (redwoodjs#5914) fix: temporarily disable telemetry on windows (redwoodjs#5899) fix(deps): update dependency dotenv-webpack to v7.1.1 (redwoodjs#5909) fix(deps): update dependency dotenv-defaults to v5.0.2 (redwoodjs#5908) fix(deps): update dependency webpack-dev-server to v4.9.3 (redwoodjs#5906) fix(deps): update dependency core-js to v3.23.4 (redwoodjs#5905) Fix single-character typo (redwoodjs#5904) chore(deps): update dependency esbuild to v0.14.49 (redwoodjs#5898) Gitpod hot reload fix (redwoodjs#5888) fix(deps): update dependency @types/aws-lambda to v8.10.101 (redwoodjs#5894) fix(deps): update dependency @testing-library/user-event to v14.2.1 (redwoodjs#5893) fix(deps): update dependency @testing-library/react-hooks to v8.0.1 (redwoodjs#5892) chore(deps): update dependency typescript to v4.7.4 (redwoodjs#5886) feat: add noire-munich to core team (redwoodjs#5891) Fix file structure display (redwoodjs#5889) Make Form generic for better TS support (redwoodjs#5867) chore(deps): update dependency npm-packlist to v5.1.1 (redwoodjs#5885) Bump framer motion version to 6.* as recommended (redwoodjs#5870) chore(deps): update dependency nodemon to v2.0.19 (redwoodjs#5884) chore(deps): update dependency firebase to v9.8.4 (redwoodjs#5879) ...
This looks like awesome stuff @Tobbe (its implementations frankly completely over the top of my head, but as a "user" i always enjoy seeing some type magic happening as soon as i pass the right generic 😃 ). I'm wondering whether you could put this into the docs so the existence / application of the |
This PR adds generics to
<Form>
that we pass on to react-hook-form for better/stronger types, especially in theonSubmit
callback.It will allow you to do this:
If you pass custom
formMethods
into the form you should put the type on the hook instead