microsoft / TypeScript

TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
https://www.typescriptlang.org
Apache License 2.0
100.29k stars 12.39k forks source link

Do not type check .js files in referenced node_modules under `--checkJs` and `--maxNodeModuleJsDepth` > 0 #23219

Open mhegazy opened 6 years ago

mhegazy commented 6 years ago

Expected: no errors in node_modules\*\*.js.

There is no really good fix for these issues. i would suggest not checking these files

apalaniuk commented 4 years ago

I'm guessing this isn't prioritized? I'd love to be able to use checkJs as a type lint step vs. simply IDE errors for some JS projects that can't be converted to TypeScript for organizational reasons (for now). I suppose a workaround might be to use @checkJs directives in source files, which seems a bit cumbersome/prone to accidental exclusion.

Not sure if this is open to outside contributions, but if so, it seems like this could respect the effective include/exclude rules rather than be against node_modules explicitly.

sandersn commented 4 years ago

@apalaniuk The best contribution you could is to add to this issue. The OP is pretty detail free. I'd like to see:

  1. A simple, self-contained repro, with full actual and expected behaviour.
  2. Multiple use cases with actual/expected behaviour.
  3. A discussion of backward compatibility considerations -- what does this mean for people who already have a jsconfig?

If you can provide any of these, it will help move the issue along; if we can decide what to do, I think doing it will be pretty easy.

Raynos commented 3 years ago

I've run into this issue and thought I could fix it with adding exclude to my jsconfig.json

+  "exclude": ["node_modules"]

I was suprised to find that tsc -p jsconfig.json still checkes node_modules even though exclude is explicitely set in the jsconfig

Raynos commented 3 years ago

A reproduction can be found on this commit for this git repo ( https://github.com/Raynos/fake-s3/commit/282fa39134611857759c1b6a81ccc5cf5d75ccd3 ).

Running npm run tsc outputs 400 typescript errors for node_modules/* but zero errors for my source code ( index.js with jsdoc ).

adomoshe commented 3 years ago

Any update on this?

Raynos commented 3 years ago

My workaround is tsc -p jsconfig.json --maxNodeModuleJsDepth 0.

For some reason it ignore maxNodeModuleJsDepth in jsconfig.json but setting it 0 explicitely fixes it for me.

adomoshe commented 3 years ago

Thanks, do you know how to fix this through react-scripts start and build or tsconfig.json? I fixed my problem locally but my real problem is when I upload to the server

Raynos commented 3 years ago

i don't compile my javascript. it's javascript, I use tsc to "lint" my jsdoc.

jespertheend commented 2 years ago

My workaround is tsc -p jsconfig.json --maxNodeModuleJsDepth 0.

This does nothing for me. I'm guessing it's because I have directly imported a bunch of node modules with import "../node_modules/some-module/dist.js"

thelinuxlich commented 2 years ago

The --maxNodeModuleJsDepth 0 trick is what solves this issue but I think it deserves more attention.

lieser commented 1 year ago

I had a similar issue. I use the TypeScript compiler for type checking my JavaScript Project, but wanted errors in external code to be ignored, without having to modify the external files (e.g. by adding a @ts-nocheck at the beginning).

Thanks to https://dev.to/15five/how-to-temporarily-ignore-errors-during-a-typescript-migration-doe I came across tsc-silent (https://github.com/evolution-gaming/tsc-silent), which is a wrapper around the TypeScript compiler with a supress option. Which in my brief test so far works for me.

Maybe that workaround is helpful for others too who find this issue.