npm @types org 包中的 TypeScript 类型
TypeScript typings in npm @types org packages
我注意到有一个 npm 组织 @types,其中包含打字包,但找不到关于它的任何文档。这些是如何使用的?
它是否意味着与 typings tool? If so, how to install them? For instance, there's a @types/openlayers
包一起使用,但 typings search npm:openlayers
returns 什么都没有。
是否要与打字工具分开使用?例如。直接用 npm
?
安装
这将是 Typescript 2.0 中推出的一项功能。这为 UMD Modules/Libraries 及其各自的定义提供了类型支持。
参见 (Built-in support for UMD module definitions) 以更好地了解当前环境类型的问题。
TypeScript 博客上的公告回答了这个问题:The Future of Declaration Files
总结:
@types
npm 组织用于使用 npm
获取类型定义。使用这些类型定义是 TypeScript 2.0 中的一项功能。
从 TypeScript 2.0 开始,不再需要 typings。 npm 组织是建立开发团队的实体。我相信 Microsoft 在 npm 中设置了 @types 组织并将 TypeScript 开发人员团队添加到该组织。 @types 组织下的包是根据 docs 使用 types-publisher 工具从 DefinitelyTyped 自动发布的。
此外,还有另一种方法可以将 types
添加到您的包中:
在你的package.json
如果您的包有主 .js
文件,您还需要在 package.json
文件中指明主声明文件。将 types
属性 设置为指向您的捆绑声明文件。例如:
{
"name": "awesome",
"author": "Vandelay Industries",
"version": "1.0.0",
"main": "./lib/main.js",
"types": "./lib/main.d.ts"
}
请注意,"typings"
字段与 "types"
同义,也可以使用。
另请注意,如果您的主声明文件名为 index.d.ts
并且位于包的根目录下(在 index.js
旁边),则无需标记 "types"
属性,但建议这样做。
关于搜索类型
For the most part, type declaration packages should always have the same name as the package name on npm, but prefixed with @types/, but if you need, you can check out https://aka.ms/types to find the package for your favorite library.
来自 - http://www.typescriptlang.org/docs/handbook/declaration-files/consumption.html
但是当我npm search @types/openlayers
时,我没有得到任何结果。但是从 Web 界面进行搜索确实 return 我得到了结果。所以我猜 npm search
不会跨组织搜索。
我注意到有一个 npm 组织 @types,其中包含打字包,但找不到关于它的任何文档。这些是如何使用的?
它是否意味着与 typings tool? If so, how to install them? For instance, there's a @types/openlayers
包一起使用,但 typings search npm:openlayers
returns 什么都没有。
是否要与打字工具分开使用?例如。直接用 npm
?
这将是 Typescript 2.0 中推出的一项功能。这为 UMD Modules/Libraries 及其各自的定义提供了类型支持。
参见 (Built-in support for UMD module definitions) 以更好地了解当前环境类型的问题。
TypeScript 博客上的公告回答了这个问题:The Future of Declaration Files
总结:
@types
npm 组织用于使用 npm
获取类型定义。使用这些类型定义是 TypeScript 2.0 中的一项功能。
从 TypeScript 2.0 开始,不再需要 typings。 npm 组织是建立开发团队的实体。我相信 Microsoft 在 npm 中设置了 @types 组织并将 TypeScript 开发人员团队添加到该组织。 @types 组织下的包是根据 docs 使用 types-publisher 工具从 DefinitelyTyped 自动发布的。
此外,还有另一种方法可以将 types
添加到您的包中:
在你的package.json
如果您的包有主 .js
文件,您还需要在 package.json
文件中指明主声明文件。将 types
属性 设置为指向您的捆绑声明文件。例如:
{
"name": "awesome",
"author": "Vandelay Industries",
"version": "1.0.0",
"main": "./lib/main.js",
"types": "./lib/main.d.ts"
}
请注意,"typings"
字段与 "types"
同义,也可以使用。
另请注意,如果您的主声明文件名为 index.d.ts
并且位于包的根目录下(在 index.js
旁边),则无需标记 "types"
属性,但建议这样做。
关于搜索类型
For the most part, type declaration packages should always have the same name as the package name on npm, but prefixed with @types/, but if you need, you can check out https://aka.ms/types to find the package for your favorite library.
来自 - http://www.typescriptlang.org/docs/handbook/declaration-files/consumption.html
但是当我npm search @types/openlayers
时,我没有得到任何结果。但是从 Web 界面进行搜索确实 return 我得到了结果。所以我猜 npm search
不会跨组织搜索。