Consumption
Downloading
Getting type declarations requires no tools apart from npm.
As an example, getting the declarations for a library like lodash takes nothing more than the following command
cmd
npminstall --save-dev @types/lodash
It is worth noting that if the npm package already includes its declaration file as described inPublishing, downloading the corresponding@types
package is not needed.
Consuming
From there you’ll be able to use lodash in your TypeScript code with no fuss.This works for both modules and global code.
For example, once you’venpm install
-ed your type declarations, you can use imports and write
ts
import*as_from"lodash";_.padStart("Hello TypeScript!",20," ");
or if you’re not using modules, you can just use the global variable_
.
ts
_.padStart("Hello TypeScript!",20," ");
Searching
For the most part, type declaration packages should always have the same name as the package name onnpm
, but prefixed with@types/
,but if you need, you can use theYarn package search to find the package for your favorite library.
Note: if the declaration file you are searching for is not present, you can always contribute one back and help out the next developer looking for it.Please see the DefinitelyTypedcontribution guidelines page for details.
The TypeScript docs are an open source project. Help us improve these pagesby sending a Pull Request ❤
Last updated: Jul 07, 2025