Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is "DefinitelyTyped"?

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

like image 633
Venkatesh Avatar asked Oct 06 '16 23:10

Venkatesh


People also ask

How do you contribute to DefinitelyTyped?

Open a pull request to the DefinitelyTyped repository and verify all the checks pass. git checkout -b add-loadable-webpack-plugin-types git add . git commit -m "Add types for the @loadable/webpack-plugin package" For this example, here is the resulting pull request for reference!

What are Typings in TypeScript?

Typings was just a tool to install those files. It is now best practice to just use npm. When you have installed those files, which basically only means downloading them and placing them in your project, the TypeScript compiler will understand* that external code and you will be able to use those libraries.

What is TypeScript declaration file?

Declaration files, if you're not familiar, are just files that describe the shape of an existing JavaScript codebase to TypeScript. By using declaration files (also called . d. ts files), you can avoid misusing libraries and get things like completions in your editor.


1 Answers

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

like image 144
Fredy Treboux Avatar answered Oct 03 '22 16:10

Fredy Treboux