{"componentChunkName":"component---src-templates-handbook-tsx","path":"/docs/handbook/declaration-files/consumption.html","result":{"data":{"markdownRemark":{"id":"02c7e256-8f75-5c1d-86e3-0cda22e385ad","excerpt":"In TypeScript 2.0, it has become significantly easier to consume declaration files, in acquiring, using, and finding them.\nThis page details exactly how to do…","html":"<p>In TypeScript 2.0, it has become significantly easier to consume declaration files, in acquiring, using, and finding them.\nThis page details exactly how to do all three.</p>\n<h1 id=\"downloading\"><a href=\"#downloading\" aria-label=\"downloading permalink\" class=\"anchor\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Downloading</h1>\n<p>Getting type declarations in TypeScript 2.0 and above requires no tools apart from npm.</p>\n<p>As an example, getting the declarations for a library like lodash takes nothing more than the following command</p>\n<pre class=\"shiki\"><div class=\"language-id\">cmd</div><div class='code-container'><code><span style=\"color: #000000\">npm install --save @types/lodash</span></code></div></pre>\n<p>It is worth noting that if the npm package already includes its declaration file as described in <a href=\"/64645d69c64c0ee1ae93dc26c8b47728/Publishing.md\">Publishing</a>, downloading the corresponding <code>@types</code> package is not needed.</p>\n<h1 id=\"consuming\"><a href=\"#consuming\" aria-label=\"consuming permalink\" class=\"anchor\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Consuming</h1>\n<p>From there you’ll be able to use lodash in your TypeScript code with no fuss.\nThis works for both modules and global code.</p>\n<p>For example, once you’ve <code>npm install</code>-ed your type declarations, you can use imports and write</p>\n<pre class=\"shiki\"><div class=\"language-id\">ts</div><div class='code-container'><code><span style=\"color: #0000FF\">import</span><span style=\"color: #000000\"> </span><span style=\"color: #0000FF\">*</span><span style=\"color: #000000\"> </span><span style=\"color: #0000FF\">as</span><span style=\"color: #000000\"> _ </span><span style=\"color: #0000FF\">from</span><span style=\"color: #000000\"> </span><span style=\"color: #A31515\">\"lodash\"</span><span style=\"color: #000000\">;</span>\n<span style=\"color: #000000\">_.padStart(</span><span style=\"color: #A31515\">\"Hello TypeScript!\"</span><span style=\"color: #000000\">, </span><span style=\"color: #09835A\">20</span><span style=\"color: #000000\">, </span><span style=\"color: #A31515\">\" \"</span><span style=\"color: #000000\">);</span></code></div></pre>\n<p>or if you’re not using modules, you can just use the global variable <code>_</code>.</p>\n<pre class=\"shiki\"><div class=\"language-id\">ts</div><div class='code-container'><code><span style=\"color: #000000\">_.padStart(</span><span style=\"color: #A31515\">\"Hello TypeScript!\"</span><span style=\"color: #000000\">, </span><span style=\"color: #09835A\">20</span><span style=\"color: #000000\">, </span><span style=\"color: #A31515\">\" \"</span><span style=\"color: #000000\">);</span></code></div></pre>\n<h1 id=\"searching\"><a href=\"#searching\" aria-label=\"searching permalink\" class=\"anchor\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Searching</h1>\n<p>For the most part, type declaration packages should always have the same name as the package name on <code>npm</code>, but prefixed with <code>@types/</code>,\nbut if you need, you can check out <a href=\"https://aka.ms/types\">https://aka.ms/types</a> to find the package for your favorite library.</p>\n<blockquote>\n<p>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.\nPlease see the DefinitelyTyped <a href=\"http://definitelytyped.org/guides/contributing.html\">contribution guidelines page</a> for details.</p>\n</blockquote>","headings":[{"value":"Downloading","depth":1},{"value":"Consuming","depth":1},{"value":"Searching","depth":1}],"frontmatter":{"permalink":"/docs/handbook/declaration-files/consumption.html","title":"Consumption"}}},"pageContext":{"slug":"/docs/handbook/declaration-files/consumption.html","isOldHandbook":true}}}