Typescript 的类型定义管理系统(如 tsd)的最佳解决方案是什么?

What is the best solution for type definition management system(like tsd) for Typescript?

在使用Typescript时,我们需要考虑如何解析类型定义文件(*.d.ts)。

据我所知,管理typescript定义系统的系统有以下几种。

我猜 tsd 是最古老的,那就是 origin。 但是,为什么typings需要出生?我想为打字制作定义文件有点复杂。

@types 实际上是什么?

那么,最好的解决方案是什么?

围绕 TypeScript 的打字管理生态系统背后的故事非常丰富。

首先是(现在仍然是)一个名为 DefinitelyTyped 的整体存储库,它被用作所有想要为不同库贡献类型的开发人员的中心。

因为这个存储库,一个名为 tsd 的打字管理器直接从该存储库中获取打字并将它们保存在您的项目中。

与此同时,DT 存储库超出了它的扩展能力并且 had to be restructured。讨论进一步讨论了 d.ts. 文件应该是什么样子,所以有一次需要另一种方法来将类型包括在您的项目中。另一个问题是库和 TypeScript 编译器本身的版本控制。

然后有一次 Blake Embrey 创建了一个名为 typings 的新打字管理器,它支持 DefinitelyTyped 和新提议的构建 d.ts 的方法。新结构允许两种类型的模块——全局变量(大多数 DefinitelyTyped 模块)和应该被封装的模块。

稍后TypeScript 2.0 Beta was announced by Microsoft. The team behind TypeScript realized the need of a different way in handling typing files. What they did was a @types npm scope, which they announced will be the new way of handling typings。目前 @types 仅适用于 TypeScript 2.0。

Declaration files (.d.ts files) are a fundamental part of using existing JavaScript libraries in TypeScript, but getting them has always been a place where we’ve known there was room for improvement. As we get closer to TypeScript 2.0, we’re very excited to show off a sneak peak of our plan to simplify things. Getting type declarations in TypeScript 2.0 will require no tools apart from npm.

所以回答你的问题:

如果您使用低于 v2.0 的 TypeScript,请使用 typings,但如果您使用 2.0,请使用 @types