Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Typescript throws errors in node_modules with strict compiler options

There are several github issues about why errors in node_modules are thrown although that folder is excluded in tsconfig.json. If there is any import on the lib it is included, ignoring the exclude property.

However when using stricter compiler options (i.e. strictNullChecks, noUnusedLocals, ...) and reference any lib that is not designed to work on those options, errors are thrown.

Thus whenever using such a lib it is always a decision of not using the lib or not using the compiler option. However there are big libraries/frameworks that do not support those options (i.e. Angular) so it seems like there is no way of using those options to ensure strict checks in the own project.

Am I missing some possibility to avoid errors in node_modules being thrown? If not, is there any technical requirement to apply those rules to all imported libraries or what is the reasoning behind this behaviour?

like image 812
Aides Avatar asked Jun 01 '17 10:06

Aides


1 Answers

In all my projects setup I have structure where in root I have:

Folders:

  • code_folder
  • node_modules

Files:

  • package.json
  • README.md
  • tsconfig.json
  • tslint.json
  • yarn.lock

Then in tsconfig.json:

{
    "compilerOptions": {
        "lib": ["es6"]
    },
    "include": [
        "code_folder/*"
    ]
}
like image 117
lesyk Avatar answered Oct 18 '22 11:10

lesyk