I have read the docs about styled components tooling. I have been able to use styled components without the babel plugin, but I have not been able to use style components with the babel plugin. From reading the docs, my impressions is that my best bet is to use the styled components macro.
My project uses
- un-ejected create-react-app
- TypeScript.
I have installed the following packages:
"dependencies": {
"styled-components": "^4.0.0"
},
"devDependencies": {
"@types/styled-components": "^4.0.1",
"babel-plugin-macros": "^2.4.2",
"babel-plugin-styled-components": "^1.8.0"
},
And here I use styled components in a .tsx file:
import styled from 'styled-components/macro';
Unfortunately I get this error:
[ts] Could not find a declaration file for module 'styled-components/macro'. '/Users/.../styled-components/dist/styled-components-macro.cjs.js' implicitly has an 'any' type.
I can get it to work by removing the /macro part of the import statement, but then I miss out on more readable class names during debugging as I understand it.
@types/styled-componentsdoes not know about thestyled-components/macromodule. You can always writedeclare module "styled-components/macro";in a new.d.tsfile to declare the module as typeany, but that won't give you type information. What does the API for thestyled-components/macromodule actually look like? Is it really identical to that of the mainstyled-componentsmodule? - Matt McCutchen