【问题标题】:How to handle a project with multiple tsconfig.json files?如何处理具有多个 tsconfig.json 文件的项目?
【发布时间】:2016-02-10 15:59:47
【问题描述】:

我正在从事一个结构如下的项目:

\
|- built
|- src
|- perf
   |- tsconfig.json
|- typings
|- tsconfig.json

我的tsconfig.json 在根目录

"target": "es6",
"outDir": "built",
"rootDir": "./src",

我需要对 perf 文件夹进行不同的配置,例如不同的目标。

"target": "es5",

但是,我的 typings 文件夹位于我的项目的根目录中,而不是在 perf 文件夹中。所以执行tsc ./perf 会导致很多错误。

有没有办法告诉 TypeScript 在哪里寻找 typings?我正在使用

npm install -g typescript@next
// typescript@1.8.0-dev.20151109

或者根据文件夹有不同配置的方法?

【问题讨论】:

标签: typescript tsconfig


【解决方案1】:

有没有办法告诉 TypeScript 在哪里寻找类型

最快的解决方案

typings 移动到首选项中。

长期解决方案

一旦tsc 支持filesGlob 就使用它:https://github.com/Microsoft/TypeScript/issues/1927

【讨论】:

    【解决方案2】:

    您可以通过扩展您的基本 tsconfig.json 文件来做到这一点:

    tsconfig extension

    只是不要排除基础 tsconfig.json 中的目录,打字稿应该能够为你解析你的打字(知道这是真的,使用 node_modules/@types 或打字模块)

    例如:

    configs/base.json:

    {
      "compilerOptions": {
        "noImplicitAny": true,
        "strictNullChecks": true
      }
    }
    

    tsconfig.json:

    {
      "extends": "./configs/base",
      "files": [
        "main.ts",
        "supplemental.ts"
      ]
    }
    

    tsconfig.nostrictnull.json:

    {
       "extends": "./tsconfig",
       "compilerOptions": {
         "strictNullChecks": false
       }
    }
    

    【讨论】:

    • 仅链接的答案在内容更改或删除时无用。在您的答案中包含页面的相关部分,以回答问题。
    • 那是无法识别的。这意味着我不能拥有多个 tsconfig。
    猜你喜欢
    • 2018-12-08
    • 1970-01-01
    • 1970-01-01
    • 2020-12-29
    • 1970-01-01
    • 1970-01-01
    • 2011-02-23
    • 2016-05-04
    • 2023-04-07
    相关资源
    最近更新 更多