Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Types: Could not find a declaration file for module 'styled-components/native is back again #3772

Closed
andrewrt opened this issue Jul 13, 2022 · 3 comments

Comments

@andrewrt
Copy link

I am seeing the TS fail for styled-components/native import for React Native again.

I was previously helped by #2099 - but it appears a new release somewhere may have broken the fixes in @types/styled-components-react-native ?

I've managed to reproduce with a totally fresh / empty RN project (steps to create below): https://github.com/andrewrt/StyledTSTest

Environment

System:
 - OS: macOS 11.6.1
 - CPU: (8) x64 Intel(R) Core(TM) i7-6820HQ CPU @ 2.70GHz
 - Memory: 282.90 MB / 16.00 GB
 - Shell: 5.8 - /bin/zsh
 Binaries:
 - Node: 14.17.0 - /usr/local/bin/node
 - Yarn: 1.22.17 - /usr/local/bin/yarn
 - npm: 6.14.8 - /usr/local/bin/npm
 - Watchman: 2022.02.28.00 - /usr/local/bin/watchman
 npmPackages:
 - styled-components: ^5.3.5 => 5.3.5

Also:

➜  StyledTSTest git:(master) tsc --version
Version 4.5.4

Steps to reproduce

npx react-native init StyledTSTest  --template react-native-template-typescript
cd StyledTSTest
npm i --save styled-components
npm i --save-dev @types/styled-components-react-native
npm i --save-dev @types/styled-components

add to App.tsx:

import styled from 'styled-components/native';

const SComp = styled.View`
  height: 100%;
  width: 100%;
  background-color: red;
`;

run and get

tsc --noEmit

App.tsx:30:20 - error TS7016: Could not find a declaration file for module 'styled-components/native'. '/Users/andrew/code/js/rn/StyledTSTest/node_modules/styled-components/native/dist/styled-components.native.cjs.js' implicitly has an 'any' type.

30 import styled from 'styled-components/native';
                      ~~~~~~~~~~~~~~~~~~~~~~~~~~

Expected Behavior

no TS error

Actual Behavior

TS error:

App.tsx:30:20 - error TS7016: Could not find a declaration file for module 'styled-components/native'. '/Users/andrew/code/js/rn/StyledTSTest/node_modules/styled-components/native/dist/styled-components.native.cjs.js' implicitly has an 'any' type.

30 import styled from 'styled-components/native';
                      ~~~~~~~~~~~~~~~~~~~~~~~~~~
@andrewrt
Copy link
Author

adding

  "types": ["jest", "node", "styled-components-react-native"],                           /* Type declaration files to be included in compilation. */

to tsconfig.json removes the error.
I was under the impression that the types field was optional?

@marksyzm
Copy link

marksyzm commented Jul 18, 2022

adding

  "types": ["jest", "node", "styled-components-react-native"],                           /* Type declaration files to be included in compilation. */

to tsconfig.json removes the error. I was under the impression that the types field was optional?

That isn't working for me, running react native 0.69.1

Edit: Ah, it's because of this:
DefinitelyTyped/DefinitelyTyped#59765

@Roka20012
Copy link

The problem appears after upgrading to typescript version 5.1.6

With typescript v 4.9.5 everything is okay

Does somebody have the same issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants