What is Definitely?

I see that "DefinitelyTyped" is something related to TypeScript / JavaScript development, but I could not understand its use or sample code to understand it.

I looked at http://definitelytyped.org/ and http://bartvds.imtqy.com/projects/dt.html , but couldn't figure it out better.

Any pointers, article, sample code are greatly appreciated.

+23
typescript typescript-typings definitelytyped
source share
2 answers

TypeScript allows you to have declaration files, which are files that allow you to describe the form of code written (for example) in plain JavaScript. Thus, referring to one of these files, you tell TypeScript exactly how the code or JavaScript library that you use should be considered "typed." Of course, this means that the declaration file must be carefully written and synchronized with the JavaScript library that you use.

Typed is definitely the most popular ad file repository for many JavaScript libraries, most of which do not provide their own ad files (since they are not developed using TypeScript and do not work with it). Thus, it contains community-supported declaration files

Using the DefinitiveTyped 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). In addition, being very popular, DefiniteTyped will oversee the community to contain valid creatives (although web development is something that moves very fast, you may end up with a couple of problems, especially in obscure libraries).

+47
source share

The above description is pretty clear, however, if you are like me, maybe the code below can help you get the big picture.

For example, in your project there is a lodash package, you import and use its method.

 import random from 'lodash/random'; const result = random(????); 

You can stop and ask how many parameters this method may require? and what is the data for each parameter? You should find the lodash homepage, find the random API documentation to know how to use it. After completing a bunch of tasks, you can specify the wrong order of parameters, but nothing will be displayed until you start your application and get an error.

This is where DefinitelyType shows its strength. After Installing Definitely Lodash Type

 yarn add @types/lodash 
  • when you start to enter a random method, a tooltip will show how to use the parameters.
  • if you provide the wrong parameter data type, it will show an error so that you know and correct it immediately.

Does this make sense? if not, don’t worry, turn off the music and listen to this video , I’m sure you will understand it.

+9
source share

All Articles