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

176 type errors after react-native init #94

Closed
alexanderjarvis opened this issue Oct 24, 2019 · 10 comments
Closed

176 type errors after react-native init #94

alexanderjarvis opened this issue Oct 24, 2019 · 10 comments

Comments

@alexanderjarvis
Copy link

Bug

176 typescript errors after initialising project with typescript template (using community cli).

Environment info

React native info output:

info Fetching system and libraries information...
System:
    OS: macOS 10.15
    CPU: (12) x64 Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz
    Memory: 379.68 MB / 16.00 GB
    Shell: 3.0.2 - /usr/local/bin/fish
  Binaries:
    Node: 12.11.1 - /usr/local/bin/node
    Yarn: 1.19.1 - /usr/local/bin/yarn
    npm: 6.11.3 - /usr/local/bin/npm
    Watchman: 4.9.0 - /usr/local/bin/watchman
  SDKs:
    iOS SDK:
      Platforms: iOS 13.1, DriverKit 19.0, macOS 10.15, tvOS 13.0, watchOS 6.0
    Android SDK:
      API Levels: 28, 29
      Build Tools: 28.0.3, 29.0.2
      System Images: android-28 | Google APIs Intel x86 Atom_64, android-28 | Google Play Intel x86 Atom, android-29 | Google APIs Intel x86 Atom
  IDEs:
    Android Studio: 3.5 AI-191.8026.42.35.5900203
    Xcode: 11.1/11A1027 - /usr/bin/xcodebuild
  npmPackages:
    react: 16.9.0 => 16.9.0 
    react-native: 0.61.2 => 0.61.2

Library version: latest (from cli)

Steps To Reproduce

npm i -g @react-native-community/cli
react-native init test --template react-native-template-typescript
cd test
yarn tsc

Describe what you expected to happen:

  1. No errors

Reproducible sample code

n/a

@alexanderjarvis
Copy link
Author

Fixed by:

yarn remove @types/react

@MateusAndrade
Copy link
Member

I think that removing the react types, don't like the best solution. Since at the end, you will need to use these types on your application.

Did you find anything that can explain why is this related to @types/react?

@alexanderjarvis
Copy link
Author

They are currently included by @types/react-native – that's the issue.

Perhaps the fix is not in this project but in @types/react-native?

@MateusAndrade
Copy link
Member

Perhaps the fix is not in this project but in @types/react-native?

I was thinking about this. But looking at: https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/react-native, i dont find anything related to @types/react.

You can share your project with us? Maybe this can be something related to other thing.

@alexanderjarvis
Copy link
Author

@MateusAndrade Just do the steps to reproduce.

@alexanderjarvis
Copy link
Author

This is the type of error:

node_modules/@types/react-native/node_modules/@types/react/index.d.ts:2837:14 - error TS2300: Duplicate identifier 'LibraryManagedAttributes'.

2837         type LibraryManagedAttributes<C, P> = C extends React.MemoExoticComponent<infer T> | React.LazyExoticComponent<infer T>
                  ~~~~~~~~~~~~~~~~~~~~~~~~

  node_modules/@types/react/index.d.ts:2817:14
    2817         type LibraryManagedAttributes<C, P> = C extends React.MemoExoticComponent<infer T> | React.LazyExoticComponent<infer T>
                      ~~~~~~~~~~~~~~~~~~~~~~~~
    'LibraryManagedAttributes' was also declared here.

@MateusAndrade
Copy link
Member

Look at: node_modules/@types/react-native/package.json i found that the @types/react-native already got a dependency with react.

"dependencies": {
   "@types/prop-types": "*",
   "@types/react": "*"
}

Removing @types/react and running a yarn tsc runs without any problem. Also, you can use the react types. 🎉

@alexanderjarvis
Copy link
Author

Yeah so the issue is the DefinitelyTyped publisher is generating a package.json with a dependency instead of a peerDependency?

@MateusAndrade
Copy link
Member

Yeah so the issue is the DefinitelyTyped publisher is generating a package.json with a dependency instead of a peerDependency?

Thats a good question. 😄 I dont know further about how DefinitelyTyped handles this, but i dont find another reason to this problem.

@radko93
Copy link
Collaborator

radko93 commented Oct 25, 2019

Fixed by #94

@radko93 radko93 closed this as completed Oct 25, 2019
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