typescript - 在路径中包含类型,但不编译它们

oop*_*nou 5 typescript typescript-typings

我在打字稿中遇到了问题。我有以下层次结构:

.
+-- @types
|   +-- declaration1.ts
|   +-- declaration2.ts
+-- common
|   +-- utils1.ts
|   +-- utils2.ts
+-- tests
|   +-- utils1.test.ts
|   +-- utils2.test.ts
Run Code Online (Sandbox Code Playgroud)

在我的 tsconfig.json 中,我将此配置放在测试和公共资源中公开我的所有类型(或 vscode 抱怨):

{
  "compilerOptions": {
    "outDir": "build/",
  },
  "include": ["tests", "common", "@types"]
}

Run Code Online (Sandbox Code Playgroud)

我的问题是,我不想编译所有这些东西,我只想编译公共资源(它们是实用程序,我无法获得单个(甚至多个)入口点)。

所以我想输入tsc并获取一个build文件夹填充,如下所示:

.
+-- build
|   +-- common
|   |   +-- utils1.js
|   |   +-- utils2.js
// nothing else
Run Code Online (Sandbox Code Playgroud)

相反,我得到了这个:

.
+-- build
|   +-- @types
|   |   +-- declaration1.js
|   |   +-- declaration2.js
|   +-- common
|   |   +-- utils1.js
|   |   +-- utils2.js
|   +-- tests
|   |   +-- utils1.test.js
|   |   +-- utils2.test.js
Run Code Online (Sandbox Code Playgroud)

我不知道如何从编译中排除该目录。

谢谢如果有人有想法。

Fel*_* B. 0

要包含类型但不编译它们,请将它们添加到"typeRoots"您的tsconfig.json. 中的所有内容都"include"将被编译。

{
  "compilerOptions": {
    "typeRoots": [ "@types", "tests" ]
  }
}
Run Code Online (Sandbox Code Playgroud)

要忽略文件或目录,请使用该"exclude"选项,例如:

{
  "exclude": [
    "node_modules",
    "wwwroot"
  ]
}
Run Code Online (Sandbox Code Playgroud)