facebook / create-react-app

Set up a modern web app by running one command.
https://create-react-app.dev
MIT License
102.54k stars 26.78k forks source link

checkJs option ignored in tsconfig #6267

Open mobinni opened 5 years ago

mobinni commented 5 years ago

Is this a bug report?

Yes (sort of)

Did you try recovering your dependencies?

Not necessary

Which terms did you search for in User Guide?

Looked through documentation and issues, did not find relevant ticket or info.

Environment

Environment Info:

  System:
    OS: macOS 10.14
    CPU: x64 Intel(R) Core(TM) i7-4870HQ CPU @ 2.50GHz
  Binaries:
    Node: 8.11.3 - ~/.nvm/versions/node/v8.11.3/bin/node
    Yarn: 1.5.1 - /usr/local/bin/yarn
    npm: 5.6.0 - ~/.nvm/versions/node/v8.11.3/bin/npm
  Browsers:
    Chrome: 71.0.3578.98
    Firefox: 64.0.2
    Safari: 12.0
  npmPackages:
    react: 16.4.1 => 16.4.1
    react-dom: 16.4.1 => 16.4.1
    react-scripts: ^2.1.3 => 2.1.3
  npmGlobalPackages:
    create-react-app: 2.1.3

(paste the output of the command here)

Steps to Reproduce

  1. Create a react-app bootstrapping typescript
  2. Add javascript with flow typings
  3. Add checkJs: false to tsconfig.json
  4. Try to run the application -> js errors still show

Expected Behavior

I would like the checkJs to be taken into account when building the application to allow migration from a flow-based application to typescript while allowing JS to be built in but not having typescript validate it. This will also allow typescript to import JS components without validating their implicit types.

Basically I have a codebase where I was using react-scripts-ts and we were able to slowly migrate using allowJs: true and checkJs: false and have eslint cover checking the code. I realize that having types in JS files is invalid syntax, however I'm in a migration process of removing flow.

Actual Behavior

Currently checkJs option is ignored in the parent tsconfig.json.

Configuration that normally works for flow migration

    ...
    "noImplicitAny": false,
    "allowJs": true,
    "checkJs": false,

In CRA 2 the following options work:

     ...
    "noImplicitAny": false,
    "allowJs": false,

It will still compile properly with the issues and render the component, even the build will work, but this is counter-intuitive. Shouldn't allowJs false throw an error if JS is being imported on build?

Reproducible Demo

https://github.com/mobinni/cra-flow-migration

1) Run yarn start

Output:

screen shot 2019-01-24 at 2 24 52 pm

I also noticed that typescript with checkJs to true will infer types based on the defaulted value in the component and complain if something else is passed in:

screen shot 2019-01-24 at 2 26 21 pm screen shot 2019-01-24 at 2 27 57 pm

I've also tried using // @ts-nocheck/// @ts-ignore however that does not seem to take effect

mobinni commented 5 years ago

I realize that the ambiguity between babel building and how tsconfig does validation is not really a bug and that the above configuration will allow for a migration path

Timer commented 5 years ago

This sounds like a bug, maybe. Let's leave it open and get a better understanding. Thanks!

couzic commented 4 years ago

Has anyone found a solution or workaround for this problem yet ? For reasons specific to my current project, it is really bugging me right now.

ayushnawani commented 4 years ago

I am also facing this issue. Any solution yet?

tfahrenreich commented 4 years ago

Migrating a code base from flow to ts and also facing this issue

dylmye commented 2 years ago

Bumping this as it's been +2 years

bhushanlaware commented 5 months ago

I am getting the issue anyone got the solution??

kopax commented 2 months ago

I am upgrading to yarn 4 and I struggle with prisma that generate a client with js file that emit error and I want to ignore, checkJs false does not help