Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Typescript: Have non optional type for state property in its onChange handler #1225

Closed
silviuaavram opened this issue Jan 26, 2021 · 0 comments · Fixed by #1582 · May be fixed by InfiniteLove2020/gutenberg#6
Closed

Typescript: Have non optional type for state property in its onChange handler #1225

silviuaavram opened this issue Jan 26, 2021 · 0 comments · Fixed by #1582 · May be fixed by InfiniteLove2020/gutenberg#6

Comments

@silviuaavram
Copy link
Collaborator

silviuaavram commented Jan 26, 2021

Relevant code or config

Avoid doing this:

    onSelectedItemChange: ({selectedItem}) => {
      selectedItem && addSelectedItem(selectedItem)
    },

Problem description:

Since it's the handler for onSelectedItemChange the types should guarantee that selectedItem is defined.

Suggested solution:

The types use the same interface as onStateChange where all state properties are optional. Each onChange handler should extend this default interface and add its own property as non optional.

export interface UseSelectStateChange<Item>
  extends Partial<UseSelectState<Item>> {
  type: UseSelectStateChangeTypes
}

// this should be added for all on change handlers.
export interface UseSelectSelectedItemChange<Item>
  extends UseSelectStateChange<Item> {
  selectedItem: Item
}

// and then
export interface UseSelectProps<Item> {
  onSelectedItemChange?: (changes: UseSelectSelectedItemChange<Item>) => void,
 // the rest
}
@silviuaavram silviuaavram mentioned this issue Dec 19, 2022
Closed
10 tasks
@silviuaavram silviuaavram mentioned this issue Jul 15, 2023
Closed
7 tasks
mergify bot referenced this issue in SvenKirschbaum/musikbot-frontend Mar 22, 2024
[![Mend Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com)

This PR contains the following updates:

| Package | Change | Age | Adoption | Passing | Confidence |
|---|---|---|---|---|---|
| [downshift](https://downshift-js.com) ([source](https://github.com/downshift-js/downshift)) | [`^8.3.1` -> `^9.0.0`](https://renovatebot.com/diffs/npm/downshift/8.5.0/9.0.0) | [![age](https://developer.mend.io/api/mc/badges/age/npm/downshift/9.0.0?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![adoption](https://developer.mend.io/api/mc/badges/adoption/npm/downshift/9.0.0?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![passing](https://developer.mend.io/api/mc/badges/compatibility/npm/downshift/8.5.0/9.0.0?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://developer.mend.io/api/mc/badges/confidence/npm/downshift/8.5.0/9.0.0?slim=true)](https://docs.renovatebot.com/merge-confidence/) |

---

### Release Notes

<details>
<summary>downshift-js/downshift (downshift)</summary>

### [`v9.0.0`](https://github.com/downshift-js/downshift/releases/tag/v9.0.0)

[Compare Source](https://github.com/downshift-js/downshift/compare/v8.5.0...v9.0.0)

##### Features

-   V9 ([#&#8203;1582](https://github.com/downshift-js/downshift/issues/1582)) ([5b0d503](https://github.com/downshift-js/downshift/commit/5b0d5031c1c11455ba18fa1516a259b4ed9357a1))

##### BREAKING CHANGES

-   Release Downshift v9.



**Why**:
Release the changes in:

-   [https://github.com/downshift-js/downshift/pull/1580](https://github.com/downshift-js/downshift/pull/1580)
-   [https://github.com/downshift-js/downshift/pull/1579](https://github.com/downshift-js/downshift/pull/1579)
-   [https://github.com/downshift-js/downshift/pull/1583](https://github.com/downshift-js/downshift/pull/1583)

Closes [https://github.com/downshift-js/downshift/issues/1322](https://github.com/downshift-js/downshift/issues/1322).
Closes [https://github.com/downshift-js/downshift/issues/1244](https://github.com/downshift-js/downshift/issues/1244).
Closes [https://github.com/downshift-js/downshift/issues/1227](https://github.com/downshift-js/downshift/issues/1227)
Closes [https://github.com/downshift-js/downshift/issues/1225](https://github.com/downshift-js/downshift/issues/1225).



**How**:
Merged the PRs in this branch.



**Checklist**:





-   \[x] Documentation
-   \[x] Tests
-   \[x] TypeScript Types
-   \[ ] Flow Types
-   \[x] Ready to be merged 



</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update again.

---

 - [ ] If you want to rebase/retry this PR, check this box

---

This PR has been generated by [Mend Renovate](https://www.mend.io/free-developer-tools/renovate/). View repository job log [here](https://developer.mend.io/github/SvenKirschbaum/musikbot-frontend).
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
1 participant