skip library check only in node_modules

喜夏-厌秋 提交于 2021-02-07 11:17:00

问题


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.


回答1:


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;
}


来源:https://stackoverflow.com/questions/49985943/skip-library-check-only-in-node-modules

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!