【问题标题】:relationship between tsconfig.json and typings.json?tsconfig.json 和 typings.json 的关系?
【发布时间】:2017-07-07 12:57:55
【问题描述】:

我下载了一个包含 Angular2-final 的示例 .NET MVC 应用程序。该项目在根目录中有一个 typings.json,在 ng2 应用程序目录中有一个 tsconfig.json。这两个文件有什么关系?这是否代表了在 VS 中配置 TypeScript 的最新最好的方法?是否需要 typings.json 或者可以配置 tsconfig.json 以涵盖 typings.json 中的功能?这是 tsconfig.json:

{
  "compilerOptions": {
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "module": "commonjs",
    "noEmitOnError": true,
    "noImplicitAny": false,
    "outDir": "../Scripts/",
    "removeComments": false,
    "sourceMap": true,
    "target": "es5",
    "moduleResolution": "node"
  },
  "exclude": [
    "node_modules",
    "typings/index",
    "typings/index.d.ts"
  ]
}

这里是typings.json:

{
  "globalDependencies": {
    "core-js": "registry:dt/core-js#0.0.0+20160725163759",
    "jasmine": "registry:dt/jasmine#2.2.0+20160621224255",
    "node": "registry:dt/node#6.0.0+20160909174046"
  }
}

【问题讨论】:

    标签: javascript .net typescript typescript-typings tsconfig


    【解决方案1】:

    Typings 是 typescript 的类型定义管理器:https://github.com/typings/typings

    它使用 typings.json 文件,类似于 npm 使用 package.json 文件,存储项目所需的类型定义。

    tsconfig.json 是 typescript 配置文件,存储 typescript 编译器的配置。

    您不需要使用类型,并且可以使用 npmjs.org 上的@types 组织来获取类型定义:https://www.npmjs.com/~types。像这样使用 npm 安装:

    npm install --save-dev @types/<module name>
    

    然后将以下内容添加到您的 tsconfig.json 中:

      "typeRoots": [
        "../node_modules/@types"
      ]
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-11-26
      • 2018-05-10
      • 1970-01-01
      • 2022-08-05
      • 2018-10-11
      • 2016-03-15
      相关资源
      最近更新 更多