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

Add Partial to setState #1779

Merged
merged 4 commits into from
Jul 18, 2019
Merged

Add Partial to setState #1779

merged 4 commits into from
Jul 18, 2019

Conversation

pmkroeker
Copy link
Contributor

Fixes some typing issues when using keyof State as a key in setState. Fixes #1778.

Allows for this:

interface IState {
  username: string;
  password: string;
}

function onInputChange(e: Event, field: keyof IState) {
  const target = e.target as HTMLInputElement;
  setState({ [field]: target.value });
}

Without throwing errors of missing fields.

Fixes some typing issues when using `keyof State` as a key in setState. Fixes #1778.
@coveralls
Copy link

coveralls commented Jul 16, 2019

Coverage Status

Coverage increased (+0.8%) to 99.688% when pulling dcd09de on pmkroeker:patch-1 into c399a24 on preactjs:master.

@marvinhagemeister
Copy link
Member

Sweet 👍 💯 Thank you so much for the PR. Let's add a little test case to make sure were not running into this in the future again. Just declaring the component in the linked issue should do it 🎉

Copy link
Member

@JoviDeCroock JoviDeCroock left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The typings guru strikes again, great job!

Copy link
Member

@marvinhagemeister marvinhagemeister left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sweet 👍 Thank you so much for the PR🙌💯

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

Successfully merging this pull request may close these issues.

(TypeScript) Why can't I setState with an object containing the keys of my state type
4 participants