What is “DefinitelyTyped”?

后端 未结 2 1896
没有蜡笔的小新
没有蜡笔的小新 2020-12-24 05:42

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.

I

2条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-24 05:58

    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 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.

    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).

提交回复
热议问题