create-react-app icon indicating copy to clipboard operation
create-react-app copied to clipboard

checkJs option ignored in tsconfig

Open mobinni opened this issue 6 years ago • 8 comments

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 avatar Jan 24 '19 19:01 mobinni

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

mobinni avatar Jan 24 '19 20:01 mobinni

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

Timer avatar Jan 24 '19 20:01 Timer

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.

couzic avatar Apr 28 '20 11:04 couzic

I am also facing this issue. Any solution yet?

ayushnawani avatar May 08 '20 07:05 ayushnawani

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

tfahrenreich avatar May 11 '20 21:05 tfahrenreich

Bumping this as it's been +2 years

dylmye avatar Jun 01 '22 11:06 dylmye

I am getting the issue anyone got the solution??

bhushanlaware avatar Mar 27 '24 06:03 bhushanlaware

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

kopax avatar Jul 04 '24 20:07 kopax