如何使用 bower 和 npm 自动 link tsd 定义?

How to link tsd definitions automatically with bower and npm?

我正在将现有项目转换为具有许多 bower 和 npm 依赖项(bower.json 和 package.json)的 TypeScript。根据tsd github page

TSD supports discovery and linking of definitions from packages installed with node or bower. Use the link command and your tsd.d.ts will be updated with paths to the files in the node_modules or bower_modules folders.

然而,当我 运行 命令 tsd linktsd init 之后它只是说 no (new)packages to link 即使我的 package.json 是充满模块的粉笔。这让我发现,也许它并没有像我想的那样。

This feature will scan package.json and bower.json files for a typescript element. This element then contains definition or definitions sub-element that contain relative path(s) to .d.ts files:

什么?如果这个 link 功能不只是从我的 package.json 获取类型定义,它的目的是什么?此命令是否只是从我的 package.json 而不是我的 tsd.json 文件中提取 tsd 配置?那么,除了删除 tsd.json 文件之外,还有什么意义呢?

所以如果不是 tsd link,我想问是否有更好的方法来自动包含我所有依赖项的 tsd 定义。对我来说,这些都由手工管理似乎有点疯狂。

tsd link 不是一个神奇的命令。当我第一次看到这个命令时,我和你一样假设。

如果您通过 bower 或 NPM 安装新包,并且包与 .d.ts 捆绑在一起,并且在配置文件中还有一个 "typescript": { "definition": "..." },那么 .d.ts 将包含到您的 tsd.d.ts 文件如下:

/// <reference path="jquery/jquery.d.ts" />
/// <reference path="../bower_components/angular/angular.d.ts" />

如果包不提供 d.ts 文件和定义配置,则此命令无能为力。