question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Using with React-Native and TypeScript, import implicity has 'any' type

See original GitHub issue

When using styled-components/native importing default has an implicity any, causing IDE showing the following error:

Error:(2, 20) TS7016: Could not find a declaration file for module 'styled-components/native'. '/Users/<user>/Development/<project>/node_modules/styled-components/native/dist/styled-components.native.cjs.js' implicitly has an 'any' type.

Environment

System:

  • OS: macOS 10.14.2
  • CPU: (8) x64 Intel® Core™ i7-4770HQ CPU @ 2.20GHz
  • Memory: 290.28 MB / 16.00 GB
  • Shell: 3.2.57 - /bin/bash

Binaries:

  • Node: 10.14.1 - /usr/local/bin/node
  • Yarn: 1.12.3 - /usr/local/bin/yarn
  • npm: 6.4.1 - /usr/local/bin/npm

npmPackages:

  • styled-components: ^4.1.3 => 4.1.3

Reproduction

just import styled-components/native

Steps to reproduce

insert import styled from 'styled-components/native';

Expected Behavior

Don’t show TS7016 error.

Actual Behavior

Showing the following error: Error:(2, 20) TS7016: Could not find a declaration file for module ‘styled-components/native’. ‘/Users/<user>/Development/<Project>/node_modules/styled-components/native/dist/styled-components.native.cjs.js’ implicitly has an ‘any’ type.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:13 (1 by maintainers)

github_iconTop GitHub Comments

150reactions
AndreCosta101commented, Jan 20, 2021

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

38reactions
B3ns44dcommented, Dec 9, 2020

import styled from ‘styled-components/native’;

The Error was like this: Error:(2, 20) TS7016: Could not find a declaration file for module ‘styled-components/native’. ‘/Users/<user>/Development/<project>/node_modules/styled-components/native/dist/styled-components.native.cjs.js’ implicitly has an ‘any’ type.

Solution: All you have to do is edit your TypeScript Config file (tsconfig.json) and add a new key-value pair as “noImplicitAny”: false

Read more comments on GitHub >

github_iconTop Results From Across the Web

Could not find a declaration file for module 'module-name ...
'/path/to/node_modules/@ts-stack/di/dist/index.js' implicitly has an 'any' type. And yet, if I import as follows, then everything works: import ...
Read more >
How to fix error TS7016: Could not find a declaration file for ...
How to fix error TS7016: Could not find a declaration file for module 'XYZ'. 'file.js' implicitly has an 'any' type · Try `npm...
Read more >
Could not find declaration file for module 'X' Error | bobbyhadz
The error "Could not find declaration file for module" occurs when TypeScript cannot find the type declaration for a module. To solve the...
Read more >
TypeScript TS7016 Could not Find Declaration Implicitly has ...
Allow for Implicit Any Imports (tsconfig.json) · Use JavaScript Libraries with TS Support · Ensure the File Extension is TS not JS ·...
Read more >
TypeScript errors and how to fix them
TS1192. error TS1192: Module ' json5 ' has no default export. ... Import Node.js type definitions first in order to use Node.js core...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found