Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

skip library check only in node_modules

Tags:

There are several questions about disabling errors in mistyped node_modules (e.g., this one, or this one), but they all involve using the skipLibCheck compiler flag.

Are there other solutions to this problem (e.g., using include or exclude)? I have a couple of hand-written .d.ts files (stricter types than available on DefinitelyTyped) that I'd like to type check, so the wholesale disabling of typechecking on these files is not appealing.

like image 673
Felipe Avatar asked Apr 23 '18 16:04

Felipe


People also ask

What is Skip Lib check?

Skip type checking of declaration files. This can save time during compilation at the expense of type-system accuracy. For example, two libraries could define two copies of the same type in an inconsistent way. Rather than doing a full check of all d.

Should you use skipLibCheck?

Instead, Typescript will only type-check the code you use against these types. This means that as long as you aren't using the incompatible parts of imported libraries, they'll compile just fine. tl;dr, Yes, --skipLibCheck degrades type checking, and ideally we wouldn't use it.


1 Answers

There is no granular control over type checking, you either check all declaration files or none unfortunately. From compiler code:

export function skipTypeChecking(sourceFile: SourceFile, options: CompilerOptions) {
    // If skipLibCheck is enabled, skip reporting errors if file is a declaration file.
    // If skipDefaultLibCheck is enabled, skip reporting errors if file contains a
    // '/// <reference no-default-lib="true"/>' directive.
    return options.skipLibCheck && sourceFile.isDeclarationFile || options.skipDefaultLibCheck && sourceFile.hasNoDefaultLib;
}
like image 56
Titian Cernicova-Dragomir Avatar answered Oct 31 '22 20:10

Titian Cernicova-Dragomir