question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Typescript support for theme when using css prop

See original GitHub issue
  • emotion version: 10.0.6
  • react version: 16.8.0-alpha.1

Relevant code:

<span
  css={theme => ({
    fontWeight: theme.font.weight.light,
    position: "absolute",
    right: "8px",
    top: "52%"
  })}
>

What you did: Created a theme using using the emotion-theming package

What happened: No typescript support for the provided theme object.

Reproduction:

Problem description:

From the documentation, it appears the current typescript support allows you to define the theme object shape when using styled(), but not when using the css prop. Currently (and as confirmed by the documentation), the object is typed as any.

Suggested solution:

Not sure if possible, but hopefully provide some way of defining a theme type via typescript generics, even when using the css prop. It appears the type is hardcoded for the css prop to any here

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:20
  • Comments:18 (13 by maintainers)

github_iconTop GitHub Comments

9reactions
Andaristcommented, Dec 7, 2019

We have decided to include a Theme interface that can be augmented in userland. This also provided that theme to the css prop - it has been implemented in https://github.com/emotion-js/emotion/pull/1609 and will be released in the upcoming v11.

8reactions
jckwcommented, Aug 22, 2019

Any updates on this?

Read more comments on GitHub >

github_iconTop Results From Across the Web

TypeScript - Emotion
When using our JSX factory, TypeScript only allows the css prop on components that accept a className prop. This is because @emotion/react resolves...
Read more >
Theme with styled-components and Typescript - Medium
Theming in styled-components allows your app to support multiple design patterns within the same app. Imagine an amazing code editor with no ...
Read more >
reactjs - Typescript props and theming with CSS Modules
The destructuring assignment on props uses theme (without the leading $ sign). Should be styles.theme instead based on the code here. – John ......
Read more >
TypeScript - Theme UI
While most APIs in Theme UI should just work in TypeScript, there are a few advanced use cases which will differ slightly. This...
Read more >
Themes within themes with React, TypeScript and Styled ...
Finally, typography is where we will set global typography rules for this theme. We can use Styled Components' css to export some set...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found