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.

Question: should we use `allowSyntheticDefaultImports:true` or `skipLibCheck:true` in every React project?

See original GitHub issue

There are currently two ways of writing in the community:

In TypeScript Documentation it write:

import * as React from "react";

and in CRA:

https://github.com/facebook/create-react-app/blob/9123aae7a3beaba8b245f73eb0180baa7b2f8411/packages/cra-template-typescript/template/src/index.tsx#L1


For users of a library, both usages are allowed. Because CRA has enabled allowSyntheticDefaultImports and skipLibCheck.

https://github.com/facebook/create-react-app/blob/30fc0bf5ed566d9b42194d56541d278013d7928c/packages/react-scripts/scripts/utils/verifyTypeScriptSetup.js#L104-L106


But for users of the library, the problem arises:

If I write a library usingimport React from 'react';.

Then downstream users must enable allowSyntheticDefaultImports or skipLibCheck, otherwise they will not be able to use this library in Typescript.

For users who configure webpack and tsconfig themselves, it is common to turn off allowSyntheticDefaultImports and skipLibCheck(default behavior).


Question: Which of the following two methods is more recommended?

  • Force each project to force skipLibCheck.
  • Force each project to force enableSyntheticDefaultImports.
  • We should recommend the author of the library to use import * as React from 'react';, but not restrict library users to use import * as React from 'react'; or import React from 'react';

Whichever method we choose, we should specify this behavior in the react / create-react-app / TypeScript documentation website, and we should have some more detailed suggestions for the react library authors and react library users.


related issues:

@ianschmitz @gaearon @RyanCavanaugh @DanielRosenwasser @orta

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:2
  • Comments:6 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
ortacommented, Jun 6, 2020

FWIW, we recommend skipLibCheck as true since 3.9

WRT: allowSyntheticDefaultImports my personal preference is to have it off, but that depends on the RFC results in general (and probably a shift in culture overall to * as x)

0reactions
xiaoxiangmoecommented, Jun 8, 2020

This will be much faster, and I will also set skipLibCheck:true in development. But this will hide the library errors, so I usually set skipLibCheck: false when compiling in production mode.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Thinking in React
The first thing you'll want to do is to draw boxes around every component (and subcomponent) in the mock and give them all...
Read more >
Optimizing Performance - React
Use the Production Build. If you're benchmarking or experiencing performance problems in your React apps, make sure you're testing with the minified production ......
Read more >
Getting Started - React
When starting a React project, a simple HTML page with script tags might still ... Each of them can work with little to...
Read more >
How to Contribute - React
React is one of Facebook's first open source projects that is both under very active ... We do our best to keep main...
Read more >
Create a New React App
Create React App doesn't handle backend logic or databases; it just creates a frontend build pipeline, so you can use it with any...
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