如何排除文件被 tsc 处理?

问题描述

如何阻止 tsc 处理另一个需要的 Javascript 文件

我想对我的主 index.js 进行全面检查,但它requires()一个generated.js 创建的 emcc Javascript 文件,非常好,但没有通过很多tsc的检查。

我尝试将该文件添加到我的 tsconfig.json 中的排除列表中,例如:

{
  "compilerOptions": {
    "target": "es5","module": "commonjs","lib": [
        "dom","webworker"
    ],"allowJs": true,"checkJs": true,"outDir": "./dist","noImplicitAny": false,"skipLibCheck": true,"forceConsistentCasingInFileNames": true
  },"include": [
    "index.js"
  ],"exclude": [
    "generated.js"
  ]
}

但是没有效果。当我运行 tsc --build tsconfig.json 时,我收到了来自 generated.js错误提示

解决方法

默认情况下,data-solutionid 文件查找打字稿文件,而您为其提供 tsconfig.json 文件。您可以将文件扩展名从 .js 更改为 .js 以让 typescript 处理它们。所以您的 .ts 文件最终可能如下所示:

tsconfig.json