Skip to content
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

TypeScript: setFieldValue first parameter type #2806

Closed
sshanzel opened this issue Oct 6, 2020 · 3 comments
Closed

TypeScript: setFieldValue first parameter type #2806

sshanzel opened this issue Oct 6, 2020 · 3 comments
Labels

Comments

@sshanzel
Copy link

sshanzel commented Oct 6, 2020

🚀 Feature request

Current Behavior

First of all, thank you for this wonderful library. setFieldValue works wonderfully but the first parameter is purely a string which typographical error might become an issue.

Desired Behavior

Strictly define the first parameter should be part of the passed argument for the type of the initialValues if type is defined on the hooks being used (e.g. useFormikContext).

Suggested Solution

Since the Type of the initialValues is strictly defined, I think we can also identify the first parameter as keyof of the actual Type passed as an argument or the actual shape of the object.

Who does this impact? Who is this for?

TypeScript Users - So we can remove the margin for error and no debugging will be needed.

Describe alternatives you've considered

Additional context

As much as possible we try to make it as Object-Oriented as possible and which we also use TypeScript - I feel that strongly-typed string to navigate the property is a little bit off.

I am more than happy to contribute to making this Feature Request working if deemed valid. Thank you!

@johnrom
Copy link
Collaborator

johnrom commented Oct 6, 2020

this issue is a duplicate of #1334. keyof is not a good solution because fields can be nested, like:

<Formik initialValues={{ 
  name: {
    first: '',
    last: '',
  }
}} {...etc}>
  <Field name="name.first" />
</Formik>

there are attempts to make the field names, but they may not be merged for a while because they use brand new TypeScript features.

attempts:

@sshanzel
Copy link
Author

sshanzel commented Oct 6, 2020

Yes, I've realized keyof wouldn't actually be able to cut it for nested implementations but still stated it to spark some discussion. But since this is a dupe, i'll be sure to look out on those referenced PRs. Thank you!

@github-actions
Copy link
Contributor

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 60 days

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants