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

fix(types): allow using a styled component as a key inside object styles in the web runtime #4249

Merged
merged 2 commits into from
Apr 30, 2024

Conversation

iiroj
Copy link
Contributor

@iiroj iiroj commented Jan 9, 2024

In v6 it's currently not possible to use a styled-component as a key inside object styles to reference its class name, because TypeScript is not happy about:

A computed property name must be of type 'string', 'number', 'symbol', or 'any'.

This PR adds the same hack available in the older @types/styled-components package intersecting the main IStyledComponent type with the string type, available only in the web runtime.

Basically, this becomes possible:

const H1 = styled.h1({
  fontSize: '2rem'
})

const Header = styled.header({
  [H1]: {
    marginBottom: '1rem'
  }
})

I realize this can be worked around by wrapping they key in either:

  1. H1.toString()
  2. String(H1)
  3. a template string ${H1}

but in my opinion it's a bit annoying.

Would be willing to accept this PR? What kind of additional testing would this require? Currently I have developed this workaround locally inside a project using TypeScript and styled-components. I did not test if it affects the React Native runtime, but it shouldn't.

@iiroj
Copy link
Contributor Author

iiroj commented Jan 9, 2024

@quantizor
Copy link
Contributor

quantizor commented Apr 30, 2024

Slight modification:

interface IStyledComponentBase<R extends Runtime, Props extends object = BaseObject>
  extends PolymorphicComponent<R, Props>,
    IStyledStatics<R, Props>,
    StyledComponentBrand {
  defaultProps?: (ExecutionProps & Partial<Props>) | undefined;
  toString: () => string;
}

export type IStyledComponent<
  R extends Runtime,
  Props extends object = BaseObject,
> = IStyledComponentBase<R, Props> & (R extends 'web' ? string : {});

interface tends to be a lot snappier than type where you can get away with it

Copy link
Contributor

@quantizor quantizor left a comment

Choose a reason for hiding this comment

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

Thank you!

@quantizor quantizor merged commit 8010643 into styled-components:main Apr 30, 2024
5 checks passed
kodiakhq bot pushed a commit to X-oss-byte/Nextjs that referenced this pull request May 1, 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 |
|---|---|---|---|---|---|
| [styled-components](https://styled-components.com) ([source](https://togithub.com/styled-components/styled-components)) | [`6.1.8` -> `6.1.9`](https://renovatebot.com/diffs/npm/styled-components/6.1.8/6.1.9) | [![age](https://developer.mend.io/api/mc/badges/age/npm/styled-components/6.1.9?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![adoption](https://developer.mend.io/api/mc/badges/adoption/npm/styled-components/6.1.9?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![passing](https://developer.mend.io/api/mc/badges/compatibility/npm/styled-components/6.1.8/6.1.9?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://developer.mend.io/api/mc/badges/confidence/npm/styled-components/6.1.8/6.1.9?slim=true)](https://docs.renovatebot.com/merge-confidence/) |

---

### Release Notes

<details>
<summary>styled-components/styled-components (styled-components)</summary>

### [`v6.1.9`](https://togithub.com/styled-components/styled-components/releases/tag/v6.1.9)

[Compare Source](https://togithub.com/styled-components/styled-components/compare/v6.1.8...v6.1.9)

#### What's Changed

-   fix: improve types for .attrs() by [@&#8203;uhyo](https://togithub.com/uhyo) in [styled-components/styled-components#4288
-   fix(types): allow using a styled component as a key inside object styles in the web runtime by [@&#8203;iiroj](https://togithub.com/iiroj) in [styled-components/styled-components#4249
-   Upgrading babel dependencies to latest to fix CVE-2023-45133 by [@&#8203;JesseObrien](https://togithub.com/JesseObrien) in [styled-components/styled-components#4214

#### New Contributors

-   [@&#8203;uhyo](https://togithub.com/uhyo) made their first contribution in [styled-components/styled-components#4288
-   [@&#8203;iiroj](https://togithub.com/iiroj) made their first contribution in [styled-components/styled-components#4249
-   [@&#8203;JesseObrien](https://togithub.com/JesseObrien) made their first contribution in [styled-components/styled-components#4214

**Full Changelog**: styled-components/styled-components@v6.1.8...v6.1.9

</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/X-oss-byte/Nextjs).
github-merge-queue bot pushed a commit to camunda/camunda that referenced this pull request May 1, 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 |
|---|---|---|---|---|---|
| [styled-components](https://styled-components.com)
([source](https://togithub.com/styled-components/styled-components)) |
[`6.1.8` ->
`6.1.9`](https://renovatebot.com/diffs/npm/styled-components/6.1.8/6.1.9)
|
[![age](https://developer.mend.io/api/mc/badges/age/npm/styled-components/6.1.9?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![adoption](https://developer.mend.io/api/mc/badges/adoption/npm/styled-components/6.1.9?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![passing](https://developer.mend.io/api/mc/badges/compatibility/npm/styled-components/6.1.8/6.1.9?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![confidence](https://developer.mend.io/api/mc/badges/confidence/npm/styled-components/6.1.8/6.1.9?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|

---

> [!WARNING]
> Some dependencies could not be looked up. Check the Dependency
Dashboard for more information.

---

### Release Notes

<details>
<summary>styled-components/styled-components
(styled-components)</summary>

###
[`v6.1.9`](https://togithub.com/styled-components/styled-components/releases/tag/v6.1.9)

[Compare
Source](https://togithub.com/styled-components/styled-components/compare/v6.1.8...v6.1.9)

#### What's Changed

- fix: improve types for .attrs() by
[@&#8203;uhyo](https://togithub.com/uhyo) in
[styled-components/styled-components#4288
- fix(types): allow using a styled component as a key inside object
styles in the web runtime by [@&#8203;iiroj](https://togithub.com/iiroj)
in
[styled-components/styled-components#4249
- Upgrading babel dependencies to latest to fix CVE-2023-45133 by
[@&#8203;JesseObrien](https://togithub.com/JesseObrien) in
[styled-components/styled-components#4214

#### New Contributors

- [@&#8203;uhyo](https://togithub.com/uhyo) made their first
contribution in
[styled-components/styled-components#4288
- [@&#8203;iiroj](https://togithub.com/iiroj) made their first
contribution in
[styled-components/styled-components#4249
- [@&#8203;JesseObrien](https://togithub.com/JesseObrien) made their
first contribution in
[styled-components/styled-components#4214

**Full Changelog**:
styled-components/styled-components@v6.1.8...v6.1.9

</details>

---

### Configuration

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

🚦 **Automerge**: Enabled.

♻ **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.

---

- [ ] <!-- rebase-check -->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/camunda/zeebe).

<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNy4zMjEuMiIsInVwZGF0ZWRJblZlciI6IjM3LjMyMS4yIiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6WyJhdXRvbWVyZ2UiXX0=-->
@iiroj iiroj deleted the fix-object-style-reference branch May 1, 2024 08:42
renovate bot added a commit to camunda/camunda that referenced this pull request May 2, 2024
….5) (#18133)

[![Mend
Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com)

This PR contains the following updates:

| Package | Change | Age | Adoption | Passing | Confidence |
|---|---|---|---|---|---|
| [styled-components](https://styled-components.com)
([source](https://togithub.com/styled-components/styled-components)) |
[`6.1.8` ->
`6.1.9`](https://renovatebot.com/diffs/npm/styled-components/6.1.8/6.1.9)
|
[![age](https://developer.mend.io/api/mc/badges/age/npm/styled-components/6.1.9?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![adoption](https://developer.mend.io/api/mc/badges/adoption/npm/styled-components/6.1.9?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![passing](https://developer.mend.io/api/mc/badges/compatibility/npm/styled-components/6.1.8/6.1.9?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![confidence](https://developer.mend.io/api/mc/badges/confidence/npm/styled-components/6.1.8/6.1.9?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|

---

### Release Notes

<details>
<summary>styled-components/styled-components
(styled-components)</summary>

###
[`v6.1.9`](https://togithub.com/styled-components/styled-components/releases/tag/v6.1.9)

[Compare
Source](https://togithub.com/styled-components/styled-components/compare/v6.1.8...v6.1.9)

#### What's Changed

- fix: improve types for .attrs() by
[@&#8203;uhyo](https://togithub.com/uhyo) in
[styled-components/styled-components#4288
- fix(types): allow using a styled component as a key inside object
styles in the web runtime by [@&#8203;iiroj](https://togithub.com/iiroj)
in
[styled-components/styled-components#4249
- Upgrading babel dependencies to latest to fix CVE-2023-45133 by
[@&#8203;JesseObrien](https://togithub.com/JesseObrien) in
[styled-components/styled-components#4214

#### New Contributors

- [@&#8203;uhyo](https://togithub.com/uhyo) made their first
contribution in
[styled-components/styled-components#4288
- [@&#8203;iiroj](https://togithub.com/iiroj) made their first
contribution in
[styled-components/styled-components#4249
- [@&#8203;JesseObrien](https://togithub.com/JesseObrien) made their
first contribution in
[styled-components/styled-components#4214

**Full Changelog**:
styled-components/styled-components@v6.1.8...v6.1.9

</details>

---

### Configuration

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

🚦 **Automerge**: Enabled.

♻ **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.

---

- [ ] <!-- rebase-check -->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/camunda/zeebe).

<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNy4zMjEuMiIsInVwZGF0ZWRJblZlciI6IjM3LjMyMS4yIiwidGFyZ2V0QnJhbmNoIjoic3RhYmxlL29wZXJhdGUtOC41IiwibGFiZWxzIjpbImF1dG9tZXJnZSJdfQ==-->
kodiakhq bot pushed a commit to kula-app/OnLaunch that referenced this pull request May 4, 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 |
|---|---|---|---|---|---|
| [styled-components](https://styled-components.com) ([source](https://togithub.com/styled-components/styled-components)) | [`6.1.8` -> `6.1.9`](https://renovatebot.com/diffs/npm/styled-components/6.1.8/6.1.9) | [![age](https://developer.mend.io/api/mc/badges/age/npm/styled-components/6.1.9?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![adoption](https://developer.mend.io/api/mc/badges/adoption/npm/styled-components/6.1.9?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![passing](https://developer.mend.io/api/mc/badges/compatibility/npm/styled-components/6.1.8/6.1.9?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://developer.mend.io/api/mc/badges/confidence/npm/styled-components/6.1.8/6.1.9?slim=true)](https://docs.renovatebot.com/merge-confidence/) |

---

### Release Notes

<details>
<summary>styled-components/styled-components (styled-components)</summary>

### [`v6.1.9`](https://togithub.com/styled-components/styled-components/releases/tag/v6.1.9)

[Compare Source](https://togithub.com/styled-components/styled-components/compare/v6.1.8...v6.1.9)

#### What's Changed

-   fix: improve types for .attrs() by [@&#8203;uhyo](https://togithub.com/uhyo) in [styled-components/styled-components#4288
-   fix(types): allow using a styled component as a key inside object styles in the web runtime by [@&#8203;iiroj](https://togithub.com/iiroj) in [styled-components/styled-components#4249
-   Upgrading babel dependencies to latest to fix CVE-2023-45133 by [@&#8203;JesseObrien](https://togithub.com/JesseObrien) in [styled-components/styled-components#4214

#### New Contributors

-   [@&#8203;uhyo](https://togithub.com/uhyo) made their first contribution in [styled-components/styled-components#4288
-   [@&#8203;iiroj](https://togithub.com/iiroj) made their first contribution in [styled-components/styled-components#4249
-   [@&#8203;JesseObrien](https://togithub.com/JesseObrien) made their first contribution in [styled-components/styled-components#4214

**Full Changelog**: styled-components/styled-components@v6.1.8...v6.1.9

</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.

---

 - [ ] <!-- rebase-check -->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/kula-app/OnLaunch).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNy4zMzEuMCIsInVwZGF0ZWRJblZlciI6IjM3LjMzMS4wIiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6W119-->
kodiakhq bot pushed a commit to X-oss-byte/Nextjs that referenced this pull request May 8, 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 |
|---|---|---|---|---|---|
| [styled-components](https://styled-components.com) ([source](https://togithub.com/styled-components/styled-components)) | [`6.1.9` -> `6.1.10`](https://renovatebot.com/diffs/npm/styled-components/6.1.8/6.1.10) | [![age](https://developer.mend.io/api/mc/badges/age/npm/styled-components/6.1.10?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![adoption](https://developer.mend.io/api/mc/badges/adoption/npm/styled-components/6.1.10?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![passing](https://developer.mend.io/api/mc/badges/compatibility/npm/styled-components/6.1.8/6.1.10?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://developer.mend.io/api/mc/badges/confidence/npm/styled-components/6.1.8/6.1.10?slim=true)](https://docs.renovatebot.com/merge-confidence/) |

---

### Release Notes

<details>
<summary>styled-components/styled-components (styled-components)</summary>

### [`v6.1.10`](https://togithub.com/styled-components/styled-components/compare/v6.1.9...cda9ccbfeb8e9e8962f38b486b4291c3847668d9)

[Compare Source](https://togithub.com/styled-components/styled-components/compare/v6.1.9...v6.1.10)

### [`v6.1.9`](https://togithub.com/styled-components/styled-components/releases/tag/v6.1.9)

[Compare Source](https://togithub.com/styled-components/styled-components/compare/v6.1.8...v6.1.9)

#### What's Changed

-   fix: improve types for .attrs() by [@&#8203;uhyo](https://togithub.com/uhyo) in [styled-components/styled-components#4288
-   fix(types): allow using a styled component as a key inside object styles in the web runtime by [@&#8203;iiroj](https://togithub.com/iiroj) in [styled-components/styled-components#4249
-   Upgrading babel dependencies to latest to fix CVE-2023-45133 by [@&#8203;JesseObrien](https://togithub.com/JesseObrien) in [styled-components/styled-components#4214

#### New Contributors

-   [@&#8203;uhyo](https://togithub.com/uhyo) made their first contribution in [styled-components/styled-components#4288
-   [@&#8203;iiroj](https://togithub.com/iiroj) made their first contribution in [styled-components/styled-components#4249
-   [@&#8203;JesseObrien](https://togithub.com/JesseObrien) made their first contribution in [styled-components/styled-components#4214

**Full Changelog**: styled-components/styled-components@v6.1.8...v6.1.9

</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/X-oss-byte/Nextjs).
kodiakhq bot pushed a commit to X-oss-byte/Nextjs that referenced this pull request May 10, 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 |
|---|---|---|---|---|---|
| [styled-components](https://styled-components.com) ([source](https://togithub.com/styled-components/styled-components)) | [`6.1.10` -> `6.1.11`](https://renovatebot.com/diffs/npm/styled-components/6.1.8/6.1.11) | [![age](https://developer.mend.io/api/mc/badges/age/npm/styled-components/6.1.11?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![adoption](https://developer.mend.io/api/mc/badges/adoption/npm/styled-components/6.1.11?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![passing](https://developer.mend.io/api/mc/badges/compatibility/npm/styled-components/6.1.8/6.1.11?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://developer.mend.io/api/mc/badges/confidence/npm/styled-components/6.1.8/6.1.11?slim=true)](https://docs.renovatebot.com/merge-confidence/) |

---

### Release Notes

<details>
<summary>styled-components/styled-components (styled-components)</summary>

### [`v6.1.11`](https://togithub.com/styled-components/styled-components/compare/v6.1.10...v6.1.11)

[Compare Source](https://togithub.com/styled-components/styled-components/compare/v6.1.10...v6.1.11)

### [`v6.1.10`](https://togithub.com/styled-components/styled-components/compare/v6.1.9...cda9ccbfeb8e9e8962f38b486b4291c3847668d9)

[Compare Source](https://togithub.com/styled-components/styled-components/compare/v6.1.9...v6.1.10)

### [`v6.1.9`](https://togithub.com/styled-components/styled-components/releases/tag/v6.1.9)

[Compare Source](https://togithub.com/styled-components/styled-components/compare/v6.1.8...v6.1.9)

#### What's Changed

-   fix: improve types for .attrs() by [@&#8203;uhyo](https://togithub.com/uhyo) in [styled-components/styled-components#4288
-   fix(types): allow using a styled component as a key inside object styles in the web runtime by [@&#8203;iiroj](https://togithub.com/iiroj) in [styled-components/styled-components#4249
-   Upgrading babel dependencies to latest to fix CVE-2023-45133 by [@&#8203;JesseObrien](https://togithub.com/JesseObrien) in [styled-components/styled-components#4214

#### New Contributors

-   [@&#8203;uhyo](https://togithub.com/uhyo) made their first contribution in [styled-components/styled-components#4288
-   [@&#8203;iiroj](https://togithub.com/iiroj) made their first contribution in [styled-components/styled-components#4249
-   [@&#8203;JesseObrien](https://togithub.com/JesseObrien) made their first contribution in [styled-components/styled-components#4214

**Full Changelog**: styled-components/styled-components@v6.1.8...v6.1.9

</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/X-oss-byte/Nextjs).
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.

None yet

2 participants