Typescript: Duplicated identifier between React Native and ES6 Lib
See original GitHub issueExpected results
- Typescript should compile with success.
- Typescript errors should be shown in the console.
- React Native should not compile when a Typescript error occurred.
Observed results
Newly created project with the template doesn’t compile successfully. Global type declaration of react-native/index.d.ts are in conflict with typescript/lib/lib.es6.d.ts. Furthermore, Typescript errors are not show in the console.
Logs
Find below errors shown in the console of a tsc command.
node_modules/@types/react-native/globals.d.ts:92:14 - error TS2300: Duplicate identifier 'RequestInfo'.
92 declare type RequestInfo = Request | string;
~~~~~~~~~~~
node_modules/@types/react-native/index.d.ts:8844:11 - error TS2451: Cannot redeclare block-scoped variable 'console'.
8844 const console: Console;
~~~~~~~
node_modules/@types/react-native/index.d.ts:8852:18 - error TS2717: Subsequent property declarations must have the same type. Property 'geolocation' must be of type 'Geolocation', but here has type 'GeolocationStatic'.
8852 readonly geolocation: Geolocation;
~~~~~~~~~~~
node_modules/@types/react-native/index.d.ts:8855:11 - error TS2451: Cannot redeclare block-scoped variable 'navigator'.
8855 const navigator: Navigator;
~~~~~~~~~
node_modules/typescript/lib/lib.es6.d.ts:21580:13 - error TS2451: Cannot redeclare block-scoped variable 'navigator'.
21580 declare var navigator: Navigator;
~~~~~~~~~
node_modules/typescript/lib/lib.es6.d.ts:21756:13 - error TS2451: Cannot redeclare block-scoped variable 'console'.
21756 declare var console: Console;
~~~~~~~
node_modules/typescript/lib/lib.es6.d.ts:21813:6 - error TS2300: Duplicate identifier 'RequestInfo'.
21813 type RequestInfo = Request | string;
Steps to reproduce
- Create project:
react-native init ReactNativeTest --template typescript && node ReactNativeTest/setup.js - Compile Typescript (v2.9.2) manually to show errors:
tsc(ornpm run tscwith corresponding command in package.json)
Solution
-
Specify in tsconfig.json valid library files to be included in the compilation. React Native is built on top of ES6 so that would be enough:
"lib": [ "es6" ] -
@emin93 At least, it could be great if we can have Typescript output to debug app because sometimes:
- The app can run with Typescript errors triggered silently in the background without any log
- The React Native bundle.js is not generated when an error occurred and no log specifies the reason
Issue Analytics
- State:
- Created 5 years ago
- Reactions:8
- Comments:9
Top Results From Across the Web
Typescript: Duplicated identifier between React Native and ...
Solution · Specify in tsconfig.json valid library files to be included in the compilation. React Native is built on top of ES6 so...
Read more >Why is Typescript giving "Duplicate Identifier" error
The TypeScript compiler is finding type conflicts in your dependencies. One method of resolving this complaint is to include skipLibCheck: ...
Read more >Fix TS2300 Duplicate identifier error in TypeScript with React
Have you updated your " react " and "@types/ react " dependencies and now see error TS2300 and TS2717? Let me help you...
Read more >Managing ambient type definitions and dealing with the ...
Change es6 to es5 in compilerOptions 's lib property. This way TypeScript won't include ES6 type definitions. Remove core-js from node_modules .
Read more >Create React Native App using TypeScript compiled with Babel
Here's every step to creating a React Native app, written in and type checked ... Duplicated identifier between React Native and ES6 Lib)....
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

Running
tscto debug or before commit could be a temporary solution but not replace a build time error reporting ( https://github.com/ds300/react-native-typescript-transformer/issues/15#issuecomment-331355513 ). I hope React Native Typescript Transformer will find a solution for this.Thanks for your help 🙂
Tks , it solved my pb =))