@types
This means that you can use these projects in a very interactive and exploratory manner, no need to have the docs open in a seperate window and making sure you don’t make a typo.
Installation is fairly simple as it just works on top of . So as an example you can install type definitions for jquery
simply as:
By default any definitions that support global consumption are included automatically. E.g. for jquery
you should be able to just start using $
globally in your project.
However for libraries (like ) I generally recommend using modules:
Module @types
Controlling Globals
As can be seen, having a definition that allows global leak-in automatically can be a problem for some teams. So you can chose to explicitly only bring in the types that make sense using the tsconfig.json
compilerOptions.types
e.g.:
The above shows a sample where only jquery
will be allowed to be used. Even if the person installs another definition like npm install @types/node
its globals (e.g. ) will not leak into your code until you add them to the tsconfig.json
types option.