如何将@types包的版本与关联的JS包的版本相关联?

问题描述 投票:0回答:1

我正在开发一个使用 typescript 2.2 的 Nodejs 项目,该项目使用 Node 6.3.1,我想从使用类型迁移到使用 @types。通过这样做,我遇到了一系列与 @types 文件的版本和相应的 npm 包之间是否存在关系相关的问题。

如果我使用 jasmine 作为示例,类型定义的现有版本是

npm show @types/jasmine@* version
@types/[email protected] '1.3.0'
@types/[email protected] '1.3.1'
@types/[email protected] '1.3.2'
@types/[email protected] '2.2.29'
@types/[email protected] '2.2.30'
@types/[email protected] '2.2.31'
@types/[email protected] '2.2.32'
@types/[email protected] '2.2.33'
@types/[email protected] '2.2.34'
@types/[email protected] '2.5.35'
@types/[email protected] '2.5.36'
@types/[email protected] '2.5.37'
@types/[email protected] '2.5.38'
@types/[email protected] '2.5.39'
@types/[email protected] '2.5.40'
@types/[email protected] '2.5.41'
@types/[email protected] '2.5.42'
@types/[email protected] '2.5.43'
@types/[email protected] '2.5.44'
@types/[email protected] '2.5.45'
@types/[email protected] '2.5.46'

但是如果我检查我拥有的 jasmine 软件包的版本;

npm show jasmine@* version
[email protected] '2.0.1'
[email protected] '2.1.0'
[email protected] '2.1.1'
[email protected] '2.2.0'
[email protected] '2.2.1'
[email protected] '2.3.0'
[email protected] '2.3.1'
[email protected] '2.3.2'
[email protected] '2.4.0'
[email protected] '2.4.1'
[email protected] '2.5.0'
ja[email protected] '2.5.1'
[email protected] '2.5.2'
[email protected] '2.5.3'

假设我使用的是 2.4.0 版本的 jasmine,我应该选择哪个版本的 @types/jasmine?因为即使我使用两者的最新版本,2.5.46 也与 2.5.3 不匹配。

另一个例子是node本身,@types中基本上有6.0或7.0版本,而typings只有下面所示的版本,6.0报告为已过时。那么,这些类型实际上与哪个版本的节点相关联?

typings view dt~node --versions
TAG                  VERSION DESCRIPTION COMPILER LOCATION
                          UPDATED
7.0.0+20170322231424 7.0.0                        github:DefinitelyTyped/DefinitelyTyped/node/index.d.ts#a4a912a0cd1849fa7df0e5d909c8625fba04e49d 2017-03-22T23:14:24.000Z
6.0.0+20161121110008 6.0.0                        github:DefinitelyTyped/DefinitelyTyped/node/node.d.ts#fb7fbd28b477f5e239467e69397ed020d92817e7  2016-11-21T11:00:08.000Z

谢谢

node.js typescript npm typescript-typings definitelytyped
1个回答
24
投票

DefinitelyTyped 包的主要和次要版本应该对应于它们所类型的包的主要和次要版本。每当 .d.ts 文件因其他原因发生更改时,补丁版本都会增加。由于次要版本不应代表重大更改,因此理论上,您可以使用可用于

2.x.y
库的最高
2.a.b.c
定义文件。

但现在警告开始了。

  • 定义文件中的标头可能没有在正确的时间更改
  • 库作者不一定遵循 semver*
  • 定义文件在任何给定点、任何方向都可能不是 100% 正确(即在 2.5 版本下列出 2.6 功能,或未能在 2.5 文件中列出 2.4 功能)

*
事实上,没有人这样做


详细解释可以参见官方文档 FAQ:
Definitely Typed 包版本与对应库的版本有什么关系?

© www.soinside.com 2019 - 2024. All rights reserved.