Typescript Type support for style objects
See original GitHub issueI’m working with React Typescript and Emotion. So far I have used template strings, but I’d like to gradually move to style objects. I’d like to be able to declare a style object, get type support from the editor, and then pass it to a css function, or a styled component. CSSProperties type by @types/react provides such support (only valid css properties could be keys). but emotion css function doesn’t accept parameters of that type. It does accept CSSObject (by Emotion), but that type accepts any key. The solution I currently use is:
export type CSSObj = Pick<CSSObject, keyof CSSProperties>
This works well. Is there a “native” emotion way to do this? If there isn’t, perhaps such a type could be added. I’d be happy to prepare a PR.
emotion
version: 9.2.12react
version: 16.7
Issue Analytics
- State:
- Created 5 years ago
- Reactions:11
- Comments:6 (3 by maintainers)
Top Results From Across the Web
Type for style attribute passed to function - Stack Overflow
I want to know how to properly declare it so that it checks the types of its arguments the way typescript does for...
Read more >TypeScript and React: Styles and CSS - fettblog.eu
Every React HTML element has a style property that allows an object with all your styling. ... TypeScript support comes through DefinitelyTyped :...
Read more >Documentation - Creating Types from Types - TypeScript
An overview of the ways in which you can create more types from existing types.
Read more >Rosebox: CSS in Typescript - Level Up Coding - gitconnected
Rosebox is a CSS-in-Typescript library that provides features like strong types(e.g., Angle ), typed functions (e.g., linearGradient ) ...
Read more >Using styled-components in TypeScript: A tutorial with examples
Here, you can learn how to build and style a TypeScript app using ... One of the best things about styled-components is that...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Just one update: this is the type that I use, if anybody is curious.
So to sum it up - if this is still something that is problematic, please raise a PR against #1501. Other than that I don’t think there is anything else actionable here right now, so I’m going to close the issue to clean up the issue tracker.
Be sure though that we care about DX a lot so if this still somehow bothers you and you cannot raise a PR yourself then please open a new issue explaining the exact problem and ideally with proposed solution.