Disable type checking for node_modules entirely
See original GitHub issueSearch Terms
skipLibCheck node_modules ignore library exclude
Suggestion
Either a new option or the existing option skipLibCheck
should be able to disable type checking for node_modules.
Use Cases
A library author might have a faulty import or might only provide typescript files for his library and not transpiled code. As a user of this library I want to be able to disable type checking for a library (or all) because I trust this library has been tested enough in other ways.
Another issue where I found a library shipping ts files and causing errors for the user: https://github.com/microsoft/TypeScript/issues/15363
The response at the end is very relevant
I understand that libraries shouldn’t publish
*.ts
files, but sometimes, they just do, and we can’t control every other library easily. I think typescript should not try to apply this kind of setting (herenoImplicitAny
) to thenode_modules
simply because it is meant to be applied to the user code being compiled, not the external dependencies.
_Originally posted by @victornoel in https://github.com/microsoft/TypeScript/issues/15363#issuecomment-309459043_
Examples
I had the case that a library came with a dist/
folder and almost all types were perfectly arranged in .d.ts files. But one file was making an import from ../index.d.ts
(which seems to be for development purposes, the lib main file is dist/index.d.ts
) which in turn then imported src/ClassA.ts
The library author used a different tsconfig and didn’t use strict type checking, but I do and that’s why the type check fails for me, because now the typescript source files of the library author are type checked.
Checklist
My suggestion meets these guidelines (in case of a new option):
- This wouldn’t be a breaking change in existing TypeScript/JavaScript code
- This wouldn’t change the runtime behavior of existing JavaScript code
- This could be implemented without emitting different JS based on the types of the expressions
- This isn’t a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, etc.)
- This feature would agree with the rest of TypeScript’s Design Goals.
Issue Analytics
- State:
- Created 3 years ago
- Reactions:47
- Comments:23 (5 by maintainers)
Top GitHub Comments
Can we please get a flag to suppress any error messages from files originating from
node_modules
? Doesn’t matter if there are 1 million errors if they are innode_modules
, just ignore them, don’t display them, and exit with code 0. The only time when we should exit with code 1 is when there are errors anywhere else other thannode_modules
skipLibCheck
is NOT a solution, it’s going to disabled ALL declaration files checks, including YOURS!An example of unwanted error:
Okay, so? I don’t really mind that there are type errors on the libraries we use, I only mind that there are type errors on the codes that we wrote anywhere else other than
node_modules
.I have 121 errors all of which are from
node_modules
.Can someone explain what’s the reasoning why we would want to be blocked by errors coming from
node_modules
? I want to implement atsc --noEmit
on a github check so that every PR will be checked before we event want to review the changes. When the github check fails, we should not be able to merge the PR because the check ensures code quality.We have been forced to disable
strict: true
on all our repos.Third-party libraries ship only
.ts
files. Thepackage.json
has entry point asindex.ts
. After a year of requests and pressure, no progress has been made convincing other companies to make changes to what they publish.The code compiles properly, and works at runtime. However, we wish to have
strict: true
enabled in our builds. However this is not possible. Required packages publish only raw.ts
files, which do not meetstrict: true
, preventing automated enforcement of standards within code that we do have control over.Being unable to enable any strict typing, solely because we consume third-party packages that don’t meet the same strictness, and of which we have no leverage for change:
any
,../../node_modules/@***/***/src/sdk/*****Api.ts:302:9 - error TS2322: Type '(value?: void | PromiseLike<void>) => void' is not assignable to type '(value?: unknown) => void'
../../node_modules/@***/***/src/sdk/*****Api.ts:21:16 - error TS2532: Object is possibly 'undefined'
We have a manual process that is sometimes applied:
tsc --noEmit --project tsconfig-strict.json
,errors
fromnode_modules/
.ts file only librariesI had suggested something similar to this : https://github.com/microsoft/TypeScript/issues/44205. But it was rejected as “configuration issue”.