If you add styled-components
to your React Native project, there's a sub-directory for the native components specifically:
import styled from 'styled-components/native`;
export const Container = styled.View`
...
`;
If you try to do this in a React Native TypeScript project, you'll run into the following typings error:
Could not find a declaration file for module 'styled-components/native'.
The typical approach to resolving this would be to install the @types/styled-components
module in your dev dependencies, however this does not resolve the issue.
If anybody has @types/styled-components-react-native
installed and still gets the error maybe it helps the trick as described at https://github.com/styled-components/styled-components/issues/2370. For me it helped to add the types to tsconfig.json
file:
{
"extends": "some/tsconfig.base",
"compilerOptions": {
// ...
"types": [
"jest",
"cypress",
"@testing-library/cypress",
"@types/styled-components-react-native"
]
},
// ...
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With