typescript - 设置 tsconfig "files"vs "include"的最佳实践?

标签 typescript tsconfig

我想知道在 tsconfig 中使用"file"与“包含”有什么好处和优缺点?

我不太喜欢包含模式,因为它只是将所有 ts 文件包含在 src 文件夹中,我现在可能想要它。

我喜欢"file"方法,因为我可以指向入口文件并加载文件需要的所有内容。

我正在使用带有 webpack 的 typescript 。我猜入口点是在 webpack 中定义的,所以也不需要在 typescript 中定义?

我尝试使用"file",但似乎无法设置文件夹来查找自定义类型定义:typescript with tsconfig with "files" => import image module not found

最佳答案

two examplestsconfig.json在 TypeScript 官网上展示——一个带有 "files" 的属性,另一个与 "include""exclude"指定的属性:

Using the "files" property

{
    "compilerOptions": {
        // irrelevant
    },
    "files": [
        "core.ts",
        "sys.ts",
        "types.ts",
        "scanner.ts",
        "parser.ts",
        "utilities.ts",
        "binder.ts",
        "checker.ts",
        "emitter.ts",
        "program.ts",
        "commandLineParser.ts",
        "tsc.ts",
        "diagnosticInformationMap.generated.ts"
    ]
}

Using the "include" and "exclude" properties

{
    "compilerOptions": {
        // irrelevant
    },
    "include": [
        "src/**/*"
    ],
    "exclude": [
        "node_modules",
        "**/*.spec.ts"
    ]
}


所以,基本上,"files"用于通过路径直接指定单独的文件,而 "include""exclude"用于定位文件或文件夹等的集合或组。

关于typescript - 设置 tsconfig "files"vs "include"的最佳实践?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51819184/

相关文章:

reactjs - react jsconfig.json 忽略路径

javascript - Angular2/Typescript/ngRx - 类型错误 : Cannot assign to read only property of object

typescript noImplicitAny 不会导致错误

typescript 错误地将元组推断为数组

visual-studio-code - VSCODE checkJs 找不到模块

typescript noEmit 用例

javascript - 在 Typescript 或 Javascript 中按数字然后字母对对象键进行排序

Angular - 如何正确测试在 Observable 订阅 block 中执行的操作?

angular - 即使安装了Typescript 3+版本,Typescript 3+功能也不起作用

angular - 如何在 Angular 5+ 中使用未编译的 TypeScript 导入 repo(并排除 .spec.ts 文件)