简体   繁体   English

如何排除文件被 tsc 处理?

[英]How to exclude files from being processed by tsc?

How do you stop tsc from processing a Javascript file required by another?你如何阻止tsc处理另一个需要的 Javascript 文件?

I want to run full checks on my main index.js , but it requires() a generated.js Javascript file created by emcc , which is perfectly fine, but doesn't pass a lot of tsc 's checks.我想对我的主index.js运行全面检查,但它requires()一个由emcc创建的generated.js Javascript 文件,这很好,但没有通过很多tsc的检查。

I tried adding the file to my exclude list in my tsconfig.json , like:我尝试将文件添加到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"
  ]
}

but that had no effect.但这没有任何效果。 When I run tsc --build tsconfig.json I get a tone of errors from generated.js .当我运行tsc --build tsconfig.json时,我从generated.js中得到了一个错误的基调。

The tsconfig.json file looks for typescript files by default, while you are providing it .js files.默认情况下, tsconfig.json文件会查找 typescript 文件,而您提供的是.js文件。 you can change the file extensions from .js to .ts to let typescript look after them.您可以将文件扩展名从.js更改为.ts以让 typescript 照顾它们。 so your tsconfig.json file may end up looking like this:所以你的tsconfig.json文件可能最终看起来像这样:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM