Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix broken typescript-checkJS script #1960

Closed
wants to merge 2 commits into from

Conversation

aweebit
Copy link
Contributor

@aweebit aweebit commented Aug 13, 2023

Problem

Currently, npm run typescript-checkJS results in

error TS6053: File 'lib/*.js' not found.
  The file is in the program because:
    Root file specified for compilation

on Windows (even when run from Git Bash), and in normal termination with no output even when there are type errors in the files on Linux and macOS.

Solution

Fix the script command.

The configuration for the JS check has been moved to a dedicated config file.

The script has been renamed to typescript-checkJs for better consistency with the TSConfig option name. (The script has been broken for a long time without someone noticing, so it is safe to assume it is not used in any contributors' custom scripts, and so the rename won't break anything.)

Peer PRs

…building upon this one

@aweebit aweebit changed the title Fix typescript-checkJS script Fix broken typescript-checkJS script. Store config in jsconfig.json so that it is picked up by VS Code Aug 13, 2023
@aweebit aweebit changed the title Fix broken typescript-checkJS script. Store config in jsconfig.json so that it is picked up by VS Code Fix broken typescript-checkJS script. Store config for the script in jsconfig.json so that it is picked up by VS Code Aug 13, 2023
@aweebit aweebit force-pushed the fix/typescript-checkJS branch 2 times, most recently from fd12ba3 to 1322cac Compare August 13, 2023 19:54
@aweebit aweebit changed the title Fix broken typescript-checkJS script. Store config for the script in jsconfig.json so that it is picked up by VS Code Fix broken typescript-checkJS script Aug 13, 2023
For better consistency with the TSConfig option name.

The script had been broken for a long time, so it is safe to assume
nobody relies on the old name in custom scripts.
@aweebit
Copy link
Contributor Author

aweebit commented Aug 13, 2023

Enough rebases, should be good to go now.

@shadowspawn
Copy link
Collaborator

The script runs fine on Mac, I use it as part of npm run test-all. I expect the underlying problem is it is relying on wildcard expansion by shell.

% npm run typescript-checkJS

> commander@11.0.0 typescript-checkJS
> tsc --allowJS --checkJS index.js lib/*.js --noEmit

% echo $?
0

@aweebit
Copy link
Contributor Author

aweebit commented Aug 13, 2023

The script runs fine on Mac, I use it as part of npm run test-all. I expect the underlying problem is it is relying on wildcard expansion by shell.

% npm run typescript-checkJS

> commander@11.0.0 typescript-checkJS
> tsc --allowJS --checkJS index.js lib/*.js --noEmit

% echo $?
0

Checked it on Debian and the result was the same as what you get.

However, it isn't correct. There are currently a lot of type errors in the code and we are supposed to see them, instead we see nothing.

@aweebit
Copy link
Contributor Author

aweebit commented Aug 13, 2023

Even when running the command for one individual file that has type errors (a lot of them) and with the exact option names from TypeScript's documentation, it still doesn't output anything:

$ npx tsc --allowJs --checkJs lib/command.js --noEmit
$ echo $?
0

So the command has been misleading the entire time even if it has been in use, so renaming it might not be a good idea.

@aweebit
Copy link
Contributor Author

aweebit commented Aug 13, 2023

@shadowspawn
Copy link
Collaborator

There are (at least!) 3 different things going on:

  • // @ts-check only works as the first line of the file
  • lib/*.js in run-script typescript-checkJS does not work on Windows
  • run-script typescript-checkJS generates far less errors than when enable checking in VSCode editor

The command-line help gives one clue, specifying the files apparently uses the default compiler options:

tsc app.ts util.ts
  Ignoring tsconfig.json, compiles the specified files with default compiler options.

I haven't yet managed to get VSCode to do the gentler type checking that typescript-checkJS implicitly uses, but it may just be difference between tsconfig.json and default compiler settings.

@shadowspawn
Copy link
Collaborator

Managed to get looser checks matching run-script in VSCode with both of these in tsconfig, so at least reproducible behaviour now:

   "checkJs": true,
   "strict": false, 

@aweebit
Copy link
Contributor Author

aweebit commented Aug 15, 2023

Closing in favor of #1969.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants