与使用打字vs npm安装类型定义文件有什么区别? [英] What's the difference from installing type definition files using typings vs npm?
问题描述
我一直在使用命令行,并从命令行使用Typings
安装TypeScript
类型定义文件.d.ts
,如下所示:
I've been using the command line and installing TypeScript
type definition files .d.ts
using Typings
from the command line like the following:
typings install dt~jquery --global --save
这很好用,如果在我项目的根目录下完成,它会安装到typings/globals
目录.
This works perfectly and if done at the root of my project, it gets installed to the typings/globals
directory.
我最近看到了一些教程,这些教程通过package.json
文件中的devDependencies
部分添加了typings
安装,以供npm
进行如下安装:
I recently had seen tutorials adding typings
installations via the devDependencies
section in the package.json
file for npm
to install like the following:
"devDependencies": {
"@types/core-js": "0.9.34"
}
我实际上做了上面的事情,甚至找不到d.ts
文件的位置,因为在node_modules
文件夹的任何地方都看不到它.
I actually did the above and couldn't even find where the d.ts
file was put as I didn't see it anywhere in the node_modules
folder.
从上述(2)方法安装键入内容之间有什么区别,如果使用npm
安装和下拉文件,键入内容文件最终会存放在哪里?
What is the difference between installing typings from the (2) methods above, and where do the typings files end up if using npm
to install and pull down the files?
推荐答案
使用npm范围软件包@types
安装类型是TypeScript 2.0中的新正式方法.请参阅 TypeScript 2.0的新增功能是什么?/简化的申报文件(.d.ts)获取
:
Installing types with npm scoped package @types
is the new official way in TypeScript 2.0. See What’s New in TypeScript 2.0? / Simplified Declaration File (.d.ts) Acquisition
:
Typings和tsd是TypeScript生态系统的绝佳工具.到目前为止,这些程序包管理器已帮助用户尽可能快地将.d.ts文件从DefinitelyTyped获取到他们的项目中.尽管有这些工具,但新用户最大的痛苦之一就是学习如何从这些程序包管理器获取和管理声明文件依赖项.
Typings and tsd have been fantastic tools for the TypeScript ecosystem. Up until now, these package managers helped users get .d.ts files from DefinitelyTyped to their projects as fast as possible. Despite these tools, one of the biggest pain points for new users has been learning how to acquire and manage declaration file dependencies from these package managers.
在2.0中获取和使用声明文件要容易得多.要获得像lodash这样的库的声明,您只需要npm:
Getting and using declaration files in 2.0 is much easier. To get declarations for a library like lodash, all you need is npm:
npm install --save @types/lodash
上面的命令安装了有作用域的软件包@ types/lodash,当在程序中的任何地方导入lodash时,TypeScript 2.0将自动引用该软件包.这意味着您不需要任何其他工具,并且.d.ts文件可以与package.json中的其他依赖项一起传输.
The above command installs the scoped package @types/lodash which TypeScript 2.0 will automatically reference when importing lodash anywhere in your program. This means you don’t need any additional tools and your .d.ts files can travel with the rest of your dependencies in your package.json.
键入文件安装在node_modules/@types
目录中.因此,您要查找的文件可以在这里找到node_modules/@types/core-js/index.d.ts
实际上,它们是简单的节点模块TS 2.0.知道如何正确处理.
The typing files are installed inside the node_modules/@types
directory. So the file you are looking for can be found here node_modules/@types/core-js/index.d.ts
In fact they are simple node-modules, TS 2.0. know how to handle properly.
这篇关于与使用打字vs npm安装类型定义文件有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!