Skip to content

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

Open

Description

@xiaoxiangmoe

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

Activity

  1. stale commented on Jun 6, 2020

    @stale

    This issue has been automatically marked as stale because it has not had any recent activity. It will be closed in 5 days if no further activity occurs.

  2. added and removed on Jun 6, 2020
  3. ianschmitz commented on Jun 6, 2020

    @ianschmitz
    Contributor

    Once the react RFC is figured out we can provide recommendations here I think.

  4. orta commented on Jun 6, 2020

    @orta
    Contributor

    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)

  5. xiaoxiangmoe commented on Jun 7, 2020

    @xiaoxiangmoe
    ContributorAuthor

    @orta why we should enable skipLibCheck since 3.9?

  6. ianschmitz commented on Jun 7, 2020

    @ianschmitz
    Contributor

    In my experience type checking is significantly faster with skipLibCheck on.

  7. xiaoxiangmoe commented on Jun 8, 2020

    @xiaoxiangmoe
    ContributorAuthor

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions