24

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.

Felipe
  • 3,003
  • 2
  • 26
  • 44
  • 1
    Wow, you even take the trouble to enhance existing lib with stricter types! Perhaps consider also amend those with wrong types? – hackape Apr 09 '19 at 19:03
  • 1
    Titian show the source code so he's probably right. Maybe consider alternative solution like [this](https://stackoverflow.com/questions/40322788/) – hackape Apr 09 '19 at 19:17
  • There's an opened [issue](https://github.com/microsoft/TypeScript/issues/30511) with a feature request for this. – cbdeveloper Jan 06 '21 at 18:08

1 Answers1

11

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;
}
Titian Cernicova-Dragomir
  • 230,986
  • 31
  • 415
  • 357
  • 3
    Is there any plans/proposals in TS compiler to change that? So it allows skipping one or more declaration files or libs? – Mina Luke Mar 28 '22 at 05:30