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.

Typescript: Duplicated identifier between React Native and ES6 Lib

See original GitHub issue

Expected 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

  1. Create project: react-native init ReactNativeTest --template typescript && node ReactNativeTest/setup.js
  2. Compile Typescript (v2.9.2) manually to show errors: tsc (or npm run tsc with corresponding command in package.json)

Solution

  1. 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" ]

  2. @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:closed
  • Created 5 years ago
  • Reactions:8
  • Comments:9

github_iconTop GitHub Comments

1reaction
nicolashemoniccommented, Jul 3, 2018

Running tsc to 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 🙂

0reactions
lawson-ngcommented, Jan 26, 2021

Expected 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

  1. Create project: react-native init ReactNativeTest --template typescript && node ReactNativeTest/setup.js
  2. Compile Typescript (v2.9.2) manually to show errors: tsc (or npm run tsc with corresponding command in package.json)

Solution

  1. 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" ]
  2. @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

Tks , it solved my pb =))

Read more comments on GitHub >

github_iconTop 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 >

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