styled-components: [v4.0.0] Types: Could not find a declaration file for module 'styled-components/native'.
there are no types for react-native components
Environment
npx: Installierte 1 in 2.983s
System:
- OS: macOS High Sierra 10.13.6
- CPU: x64 Intel® Core™ i5-6267U CPU @ 2.90GHz
- Memory: 751.21 MB / 16.00 GB
- Shell: 5.3 - /bin/zsh
Binaries:
- Node: 10.9.0 - /usr/local/bin/node
- Yarn: 1.10.1 - /usr/local/bin/yarn
- npm: 5.10.0 - /usr/local/bin/npm
- Watchman: 4.9.0 - /usr/local/bin/watchman
Reproduction
add typescript and tslint
Steps to reproduce
let tslint your code
Expected Behavior
no error
Actual Behavior
$ tslint --project tsconfig.json && yarn typecheck
$ tsc --noEmit
App.tsx(5,20): error TS7016: Could not find a declaration file for module 'styled-components/native'. '…/app/node_modules/styled-components/native/dist/styled-components.native.cjs.js' implicitly has an 'any' type.
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 19
- Comments: 47 (3 by maintainers)
styled-components/nativetypes moved to@types/styled-components-react-native.Just add:
❯yarn add @types/styled-components-react-native -DSolution: All you have to do is edit your TypeScript Config file (tsconfig.json) and add a new key value pair as: “noImplicitAny”: false
You should add
@types/styled-componentsas dependency to the project.If you are using yarn, you can run the command
This solution works for me, but just change the version to
5.1.6and runyarn installdidn’t work, so I had to:Check if your tsconfig.json does not declare
typesimplicitly or explicitly, if so, you need to add"styled-components-react-native"to it:Example:
The
"@tsconfig/react-native/tsconfig.json"base config from the react-native template defines thetypes, so I had to override it to:https://user-images.githubusercontent.com/95294257/184026064-65ee59f4-b080-4bf2-95b3-badcc12964c1.mov
@pettomartino happening to me as well on
"@types/styled-components-react-native": "^5.1.1".Edit: The problem appears to be with
@types/styled-components: "^5.1.7". Just downgrade to5.1.6and it should be fine.This solution has worked for me too. Thanks!
^ I have added
@types/styled-components-react-nativeand the problem persist. Actually I started having after updating. Any clues?Works!!!
Insert into: “compilerOptions”: { “noImplicitAny”: false }
Need to make this info more explicit in docs
Works for me, thanks!
cc @styled-components/typers
I solve the problem just by adding
to my
tsconfig.jsononcompilerOptionsI tried the below but did not work for me.
my set up-
Same error happened with
styled-componentsv4.1.1 and@types/styled-componentsv4.1.1Works for me, thanks!!
I solved problem using this command. Recommend
I can confirm this works! Thanks!
This also works for me !!
you are not solving the issue, you are turning off the ts checking
Please update the docs folks - finding the answer in a closed thread is not helpful. But glad it worked.
Cheers
any ideas on how to type now that v6.0.0 is released?
I get this error:
TS7006: Parameter 'props' implicitly has an 'any' type.This works for me Thanks
From what I gathered, in version 6 of styled-components, there’s no need to install
@types/styled-components-react-native. It seems that the typing is included by default; you just need to install styled-components.My dependencies:
To have intellisense in the themes, the configuration that worked for me was this:
In the
tsconfig.json, I didn’t add anything.This worked for me thanks, I wonder why this isn’t the default config?
Thanks this works!!