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.
bildschirmfoto 2018-10-15 um 22 37 11 bildschirmfoto 2018-10-15 um 22 38 01

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 19
  • Comments: 47 (3 by maintainers)

Most upvoted comments

styled-components/native types moved to @types/styled-components-react-native.

Just add:

❯yarn add @types/styled-components-react-native -D

Solution: 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-components as dependency to the project.

If you are using yarn, you can run the command

yarn add @types/styled-components

@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 to 5.1.6 and it should be fine.

Works for me, thanks!

This solution works for me, but just change the version to 5.1.6 and run yarn install didn’t work, so I had to:

yarn remove @types/styled-components yarn add -D @types/styled-components@5.1.6

I tried the below but did not work for me.

yarn add @types/styled-components-react-native -D

my set up-

"dependencies": {
    "react": "17.0.2",
    "react-native": "0.68.1",
    "styled-components": "5.3.5"
  },
 "devDependencies": {
   "@types/styled-components": "5.1.25",
   "@types/styled-components-react-native": "^5.1.3"
  }

Screen Shot 2022-08-03 at 9 15 29 AM

Check if your tsconfig.json does not declare types implicitly 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 the types, so I had to override it to:

    "types": ["react-native", "jest", "styled-components-react-native"],

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 to 5.1.6 and it should be fine.

Just add:

❯yarn add @types/styled-components-react-native -D

This solution has worked for me too. Thanks!

^ I have added @types/styled-components-react-native and the problem persist. Actually I started having after updating. Any clues?

“noImplicitAny”: false

Works!!!

Insert into: “compilerOptions”: { “noImplicitAny”: false }

styled-components/native types moved to @types/styled-components-react-native.

Need to make this info more explicit in docs

@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 to 5.1.6 and it should be fine.

Works for me, thanks!

I solve the problem just by adding

"types": ["styled-components-react-native"]

to my tsconfig.json on compilerOptions

I tried the below but did not work for me.

yarn add @types/styled-components-react-native -D

my set up-

"dependencies": {
    "react": "17.0.2",
    "react-native": "0.68.1",
    "styled-components": "5.3.5"
  },
 "devDependencies": {
   "@types/styled-components": "5.1.25",
   "@types/styled-components-react-native": "^5.1.3"
  }

Screen Shot 2022-08-03 at 9 15 29 AM

Same error happened with styled-components v4.1.1 and @types/styled-components v4.1.1

I tried the below but did not work for me.

yarn add @types/styled-components-react-native -D

my set up-

"dependencies": {
    "react": "17.0.2",
    "react-native": "0.68.1",
    "styled-components": "5.3.5"
  },
 "devDependencies": {
   "@types/styled-components": "5.1.25",
   "@types/styled-components-react-native": "^5.1.3"
  }

Screen Shot 2022-08-03 at 9 15 29 AM

Check if your tsconfig.json does not declare types implicitly 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 the types, so I had to override it to:

    "types": ["react-native", "jest", "styled-components-react-native"],

Screen.Recording.2022-08-10.at.18.44.51.mov

Works for me, thanks!!

yarn add @types/styled-components-react-native -D

I solved problem using this command. Recommend

Just add:

❯yarn add @types/styled-components-react-native -D

I can confirm this works! Thanks!

styled-components/native types moved to @types/styled-components-react-native.

This also works for me !!

“noImplicitAny”: false

Works!!!

Insert into: “compilerOptions”: { “noImplicitAny”: false }

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.

Screenshot 2023-06-28 at 10 34 59

styled-components/native types moved to @types/styled-components-react-native.

This works for me Thanks

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.

Screenshot 2023-06-28 at 10 34 59

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: image

To have intellisense in the themes, the configuration that worked for me was this: image

In the tsconfig.json, I didn’t add anything. image

I tried the below but did not work for me.

yarn add @types/styled-components-react-native -D

my set up-

"dependencies": {
    "react": "17.0.2",
    "react-native": "0.68.1",
    "styled-components": "5.3.5"
  },
 "devDependencies": {
   "@types/styled-components": "5.1.25",
   "@types/styled-components-react-native": "^5.1.3"
  }

Screen Shot 2022-08-03 at 9 15 29 AM

Check if your tsconfig.json does not declare types implicitly 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 the types, so I had to override it to:

    "types": ["react-native", "jest", "styled-components-react-native"],

Screen.Recording.2022-08-10.at.18.44.51.mov

This worked for me thanks, I wonder why this isn’t the default config?

Just add:

❯yarn add @types/styled-components-react-native -D

Thanks this works!!