-
-
Notifications
You must be signed in to change notification settings - Fork 355
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(core): docs for reusable fields & reusable field utility type #1084
base: main
Are you sure you want to change the base?
Conversation
View your CI Pipeline Execution ↗ for commit 524d024.
☁️ Nx Cloud last updated this comment at |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #1084 +/- ##
==========================================
+ Coverage 86.61% 86.75% +0.13%
==========================================
Files 29 29
Lines 1158 1155 -3
Branches 301 298 -3
==========================================
- Hits 1003 1002 -1
+ Misses 142 140 -2
Partials 13 13 ☔ View full report in Codecov by Sentry. |
7b64244
to
4256a04
Compare
4256a04
to
8f9ac02
Compare
92b67c7
to
616d520
Compare
Sorry for the push forces... was looking at the incorrect section of code and wondering why it wasn't changing. Friday’s for you 🙃 |
616d520
to
bb83da8
Compare
/** | ||
* The return type use useForm with pre-populated generics | ||
*/ | ||
export type UseFormReturnType<TForm, TFormValidator> = TFormValidator extends |
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 would love to get rid of the TFormValidator slot, since TFormValidator is just Validator<TForm, unknown> | undefined. But so far my efforts have been fruitless.
{({ handleChange, handleBlur, state }) => ( | ||
<input | ||
value={state.value} | ||
onChange={(e) => handleChange(e.target.value as any)} |
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.
Another improvement would be to get Ts to infer the handleChange value so the update is type safe.
A continue on from #636, this PR introduces docs for reusable components/fields as well as introduces a Ts utility type for inferring valid field names, for the relevant component.
Much like my last PR this is something I was trying to do for a work project, but not having any docs or examples hindered the process, so I figured I'd give it a go.
Guidance wanted:
Specifically with this line
onChange={(e) => handleChange(e.target.value as any)}
(line 28 in reusable-fields) I can't stand the casting of any, however I can figure a way for Ts to infer this value. Any suggestions is greatly appreciated!Sandbox
I have a code sandbox for playing around with this here, you'll see theres a folder called solutions that has two files:
The rest of the files can be ignored but if you want to see how I got here they kind of explain my reasoning.