所以最近几天我一直在尝试使用 TypeScript,但在安装外部模块的定义时遇到了问题。
如果我像这样使用 tsd
就没有问题:
tsd install express
然而,tsd
似乎已被弃用,我应该使用 typings
。
所以我尝试运行这个命令:
typings install --ambient express
这是输出:
typings INFO reference Stripped reference "https://raw.githubusercontent.com/DefinitelyTyped/DefinitelyTyped/7de6c3dd94feaeb21f20054b9f30d5dabc5efabd/serve-static/serve-static.d.ts" during installation from "express"
typings INFO reference Stripped reference "https://raw.githubusercontent.com/DefinitelyTyped/DefinitelyTyped/7de6c3dd94feaeb21f20054b9f30d5dabc5efabd/express-serve-static-core/express-serve-static-core.d.ts" during installation from "express"
express
└── (No dependencies)
然后我必须手动安装剥离的引用,当我这样做时,使用 tsc
编译时仍然会出错,但是当我使用 tsd
时,所有引用都已安装并且我在编译过程中没有遇到任何错误。
我只想尽可能简单地安装定义。
使用 tsd
是否安全,或者我将来可能会遇到一些问题?
为什么 typings
没有安装它们?
想象一下,如果你运行 npm install express
然后你得到一个依赖项列表,你必须递归地安装所有依赖项。
我应该为每个模块花费多少时间来安装定义文件?
我在网上找不到答案。其他人如何处理?
另外,如果某个模块没有可用的定义,我该怎么办?
最佳答案
正如@BrunoLM 在评论中指出的那样,随着 TypeScript 2.0 的发布,这是现在安装声明文件的方式:
npm i @types/express
引用资料:
关于javascript - 有没有简单的方法来安装 TypeScript 定义?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36520856/