Question: should we use `allowSyntheticDefaultImports:true` or `skipLibCheck:true` in every React project?
See original GitHub issueThere are currently two ways of writing in the community:
In TypeScript Documentation it write:
import * as React from "react";
and in CRA:
For users of a library, both usages are allowed. Because CRA has enabled allowSyntheticDefaultImports
and skipLibCheck
.
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 useimport * as React from 'react';
orimport 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:
- https://github.com/facebook/create-react-app/issues/7586
- https://github.com/facebook/react/issues/11503
@ianschmitz @gaearon @RyanCavanaugh @DanielRosenwasser @orta
Issue Analytics
- State:
- Created 3 years ago
- Reactions:2
- Comments:6 (5 by maintainers)
Top GitHub Comments
FWIW, we recommend
skipLibCheck
as true since 3.9WRT:
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
)This will be much faster, and I will also set
skipLibCheck:true
in development. But this will hide the library errors, so I usually setskipLibCheck: false
when compiling in production mode.