jaredpalmer / formik

Build forms in React, without the tears 😭
https://formik.org
Apache License 2.0
33.91k stars 2.78k forks source link

types: improve handlers type #3752

Closed chernodub closed 1 year ago

chernodub commented 1 year ago

Hi, I noticed that when using getFieldMeta and getFieldHelpers, IDE does not provide the list of the names of the form fields. So I made a non-breaking update to FormikHandlers interface.

This way we are able to leverage typed argument in getFieldMeta and getFieldHelpers to (1) avoid possible bugs after refactoring and (2) get a better DX when working with formik.

Example:

Screen Shot 2023-04-10 at 10 12 05

Please let me know if more updates or clarifications needed. Thanks!

vercel[bot] commented 1 year ago

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
formik-docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 9, 2023 0:29am
changeset-bot[bot] commented 1 year ago

⚠️ No Changeset found

Latest commit: 4910b4046570a7acdf2071b3ac2788521d24d8df

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

quantizor commented 1 year ago

Good start! These APIs allow for deep.path.key notation, so we'll need a utility type to extract all the deep object keys versus just the surface-level ones. Something like this could work: https://dev.to/pffigueiredo/typescript-utility-keyof-nested-object-2pa3

Pretty much everywhere we take a field name would benefit from this.

chernodub commented 1 year ago

Hi @probablyup! I was finally able to find some time to work on this, and I improved the overall implementation. Now, all the methods that accept field names are strictly-typed. I also added some tests for this. Feel free to play around in a new example project I created.

Here's a small example of how it works:

Screenshot 2023-07-09 at 15 30 22
chernodub commented 1 year ago

Seems that the repo is inactive, I'm closing the PR