javascript - tsconfig.json 和 typings.json 之间的关系?

标签 javascript .net typescript typescript-typings tsconfig

我下载了一个包含 Angular2-final 的示例 .NET MVC 应用程序。该项目在根目录中有一个 typings.json,在 ng2 应用程序目录中有一个 tsconfig.json。这2个文件是什么关系?这是否代表了在 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"
  }
}

最佳答案

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"
  ]

关于javascript - tsconfig.json 和 typings.json 之间的关系?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42307425/

相关文章:

javascript - 如何处理 Meteor 中的客户端对象?

javascript - 如何禁用 django 中的 html 按钮?

javascript - 获取复选框值,包括空格后的值

Javascript 从正文返回特定字符串

c# - 获取sql中连接列的计数

javascript - 联合类型 js 的 Typescript 定义

C#属性继承问题

.net - DLL运行时错误使我的C#应用​​程序崩溃-如何避免它?

javascript - typescript 中的单例装饰器

javascript - 更好的体验/自动化清洁和构建