什么是“绝对类型化"? [英] What is "DefinitelyTyped"?

查看:27
本文介绍了什么是“绝对类型化"?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我看到DefinitelyTyped"与 TypeScript/JavaScript 开发有关,但我无法理解它的用法或一些代码示例来理解它.

I see "DefinitelyTyped" is something related to TypeScript/JavaScript development, but I couldn't understand its use or some code sample to understand about it.

我看了http://definelytyped.org/http://bartvds.github.io/projects/dt.html 但无法更好地理解它.

I looked at http://definitelytyped.org/ and http://bartvds.github.io/projects/dt.html but couldn't understand it better.

非常感谢任何指针、文章、代码示例.

Any pointers, article, Code sample is much appreciated.

推荐答案

TypeScript 允许您拥有 声明文件,这些文件允许您描述用(例如)纯 JavaScript 编写的代码的形状.因此,通过引用这些文件之一,您可以准确地告诉 TypeScript 您正在使用的 JavaScript 代码或库应该如何被假定为类型化".当然,这意味着声明文件需要仔细编写并与您使用的 JavaScript 库同步.

TypeScript allows you to have Declaration Files which are files that allow you to describe the shape of code that's written in (for example) plain JavaScript. So, by referencing one of these files you tell TypeScript exactly how that JavaScript code or library you are using should be assumed to be "typed". Of course, this means that the declaration file need to be carefully written and in sync with the JavaScript library you are using.

DefinitelyTyped 是许多 JavaScript 库最流行的声明文件存储库,其中大多数库不提供自己的声明文件(因为它们不是用 TypeScript 开发的,也不承诺使用它).所以它保存了社区维护的声明文件.

DefinitelyTyped is the most popular repository of Declaration Files for many many JavaScript libraries most of which do not provide their own declaration files (as they are not developed with TypeScript and are not committed to work with it). So it holds Declaration files maintained by the community.

通过使用绝对类型和它包含的声明文件,您可以像使用 TypeScript 库一样使用大多数流行的 JavaScript 库,因为您将通过编译器进行类型验证(如声明文件所示).此外,由于非常受欢迎,绝对类型将由社区策划以包含有效的声明文件(尽管 Web 开发的发展速度非常快,您最终可能会发现一些问题,特别是在晦涩的库中).

By using DefinitelyTyped and the declaration files it contains you can use most of the popular JavaScript libraries as if they were TypeScript libraries in the sense that you will have type validation by the compiler (as the declaration file indicates). Also, being so popular, DefinitelyTyped will be curated by the community to contain valid declaration files (although, web development being something that moves really fast, you may end up finding a couple of issues specially in obscure libraries).

这篇关于什么是“绝对类型化"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆