{"componentChunkName":"component---src-templates-handbook-tsx","path":"/docs/handbook/declaration-files/publishing.html","result":{"data":{"markdownRemark":{"id":"8a6799a9-3227-50b6-8490-f4042efa142a","excerpt":"Now that you have authored a declaration file following the steps of this guide, it is time to publish it to npm.\nThere are two main ways you can publish your…","html":"<p>Now that you have authored a declaration file following the steps of this guide, it is time to publish it to npm.\nThere are two main ways you can publish your declaration files to npm:</p>\n<ol>\n<li>bundling with your npm package, or</li>\n<li>publishing to the <a href=\"https://www.npmjs.com/~types\">@types organization</a> on npm.</li>\n</ol>\n<p>If your package is written in TypeScript then the first approach is favored.\nUse the <code>--declaration</code> flag to generate declaration files.\nThis way, your declarations and JavaScript will always be in sync.</p>\n<p>If your package is not written in TypeScript then the second is the preferred approach.</p>\n<h1 id=\"including-declarations-in-your-npm-package\"><a href=\"#including-declarations-in-your-npm-package\" aria-label=\"including declarations in your npm package 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>Including declarations in your npm package</h1>\n<p>If your package has a main <code>.js</code> file, you will need to indicate the main declaration file in your <code>package.json</code> file as well.\nSet the <code>types</code> property to point to your bundled declaration file.\nFor example:</p>\n<pre class=\"shiki\"><div class=\"language-id\">json</div><div class='code-container'><code><span style=\"color: #000000\">{</span>\n<span style=\"color: #000000\">    </span><span style=\"color: #0451A5\">\"name\"</span><span style=\"color: #000000\">: </span><span style=\"color: #A31515\">\"awesome\"</span><span style=\"color: #000000\">,</span>\n<span style=\"color: #000000\">    </span><span style=\"color: #0451A5\">\"author\"</span><span style=\"color: #000000\">: </span><span style=\"color: #A31515\">\"Vandelay Industries\"</span><span style=\"color: #000000\">,</span>\n<span style=\"color: #000000\">    </span><span style=\"color: #0451A5\">\"version\"</span><span style=\"color: #000000\">: </span><span style=\"color: #A31515\">\"1.0.0\"</span><span style=\"color: #000000\">,</span>\n<span style=\"color: #000000\">    </span><span style=\"color: #0451A5\">\"main\"</span><span style=\"color: #000000\">: </span><span style=\"color: #A31515\">\"./lib/main.js\"</span><span style=\"color: #000000\">,</span>\n<span style=\"color: #000000\">    </span><span style=\"color: #0451A5\">\"types\"</span><span style=\"color: #000000\">: </span><span style=\"color: #A31515\">\"./lib/main.d.ts\"</span>\n<span style=\"color: #000000\">}</span></code></div></pre>\n<p>Note that the <code>\"typings\"</code> field is synonymous with <code>\"types\"</code>, and could be used as well.</p>\n<p>Also note that if your main declaration file is named <code>index.d.ts</code> and lives at the root of the package (next to <code>index.js</code>) you do not need to mark the <code>\"types\"</code> property, though it is advisable to do so.</p>\n<h2 id=\"dependencies\"><a href=\"#dependencies\" aria-label=\"dependencies 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>Dependencies</h2>\n<p>All dependencies are managed by npm.\nMake sure all the declaration packages you depend on are marked appropriately in the <code>\"dependencies\"</code> section in your <code>package.json</code>.\nFor example, imagine we authored a package that used Browserify and TypeScript.</p>\n<pre class=\"shiki\"><div class=\"language-id\">json</div><div class='code-container'><code><span style=\"color: #000000\">{</span>\n<span style=\"color: #000000\">    </span><span style=\"color: #0451A5\">\"name\"</span><span style=\"color: #000000\">: </span><span style=\"color: #A31515\">\"browserify-typescript-extension\"</span><span style=\"color: #000000\">,</span>\n<span style=\"color: #000000\">    </span><span style=\"color: #0451A5\">\"author\"</span><span style=\"color: #000000\">: </span><span style=\"color: #A31515\">\"Vandelay Industries\"</span><span style=\"color: #000000\">,</span>\n<span style=\"color: #000000\">    </span><span style=\"color: #0451A5\">\"version\"</span><span style=\"color: #000000\">: </span><span style=\"color: #A31515\">\"1.0.0\"</span><span style=\"color: #000000\">,</span>\n<span style=\"color: #000000\">    </span><span style=\"color: #0451A5\">\"main\"</span><span style=\"color: #000000\">: </span><span style=\"color: #A31515\">\"./lib/main.js\"</span><span style=\"color: #000000\">,</span>\n<span style=\"color: #000000\">    </span><span style=\"color: #0451A5\">\"types\"</span><span style=\"color: #000000\">: </span><span style=\"color: #A31515\">\"./lib/main.d.ts\"</span><span style=\"color: #000000\">,</span>\n<span style=\"color: #000000\">    </span><span style=\"color: #0451A5\">\"dependencies\"</span><span style=\"color: #000000\">: {</span>\n<span style=\"color: #000000\">        </span><span style=\"color: #0451A5\">\"browserify\"</span><span style=\"color: #000000\">: </span><span style=\"color: #A31515\">\"latest\"</span><span style=\"color: #000000\">,</span>\n<span style=\"color: #000000\">        </span><span style=\"color: #0451A5\">\"@types/browserify\"</span><span style=\"color: #000000\">: </span><span style=\"color: #A31515\">\"latest\"</span><span style=\"color: #000000\">,</span>\n<span style=\"color: #000000\">        </span><span style=\"color: #0451A5\">\"typescript\"</span><span style=\"color: #000000\">: </span><span style=\"color: #A31515\">\"next\"</span>\n<span style=\"color: #000000\">    }</span>\n<span style=\"color: #000000\">}</span></code></div></pre>\n<p>Here, our package depends on the <code>browserify</code> and <code>typescript</code> packages.\n<code>browserify</code> does not bundle its declaration files with its npm packages, so we needed to depend on <code>@types/browserify</code> for its declarations.\n<code>typescript</code>, on the other hand, packages its declaration files, so there was no need for any additional dependencies.</p>\n<p>Our package exposes declarations from each of those, so any user of our <code>browserify-typescript-extension</code> package needs to have these dependencies as well.\nFor that reason, we used <code>\"dependencies\"</code> and not <code>\"devDependencies\"</code>, because otherwise our consumers would have needed to manually install those packages.\nIf we had just written a command line application and not expected our package to be used as a library, we might have used <code>devDependencies</code>.</p>\n<h2 id=\"red-flags\"><a href=\"#red-flags\" aria-label=\"red flags 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>Red flags</h2>\n<h3 id=\"-reference-path-\"><a href=\"#-reference-path-\" aria-label=\" reference path  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><code>/// &#x3C;reference path=\"...\" /></code></h3>\n<p><em>Don’t</em> use <code>/// &#x3C;reference path=\"...\" /></code> in your declaration files.</p>\n<pre class=\"shiki\"><div class=\"language-id\">ts</div><div class='code-container'><code><span style=\"color: #008000\">/// </span><span style=\"color: #800000\">&lt;reference</span><span style=\"color: #008000\"> </span><span style=\"color: #DC0000\">path</span><span style=\"color: #000000\">=</span><span style=\"color: #A31515\">\"../typescript/lib/typescriptServices.d.ts\"</span><span style=\"color: #008000\"> </span><span style=\"color: #800000\">/&gt;</span>\n<span style=\"color: #000000\">....</span></code></div></pre>\n<p><em>Do</em> use <code>/// &#x3C;reference types=\"...\" /></code> instead.</p>\n<pre class=\"shiki\"><div class=\"language-id\">ts</div><div class='code-container'><code><span style=\"color: #008000\">/// </span><span style=\"color: #800000\">&lt;reference</span><span style=\"color: #008000\"> </span><span style=\"color: #DC0000\">types</span><span style=\"color: #000000\">=</span><span style=\"color: #A31515\">\"typescript\"</span><span style=\"color: #008000\"> </span><span style=\"color: #800000\">/&gt;</span>\n<span style=\"color: #000000\">....</span></code></div></pre>\n<p>Make sure to revisit the <a href=\"./Library%20Structures.md#consuming-dependencies\">Consuming dependencies</a> section for more information.</p>\n<h3 id=\"packaging-dependent-declarations\"><a href=\"#packaging-dependent-declarations\" aria-label=\"packaging dependent declarations 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>Packaging dependent declarations</h3>\n<p>If your type definitions depend on another package:</p>\n<ul>\n<li><em>Don’t</em> combine it with yours, keep each in their own file.</li>\n<li><em>Don’t</em> copy the declarations in your package either.</li>\n<li><em>Do</em> depend on the npm type declaration package if it doesn’t package its declaration files.</li>\n</ul>\n<h1 id=\"publish-to-types\"><a href=\"#publish-to-types\" aria-label=\"publish to types 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>Publish to <a href=\"https://www.npmjs.com/~types\">@types</a></h1>\n<p>Packages under the <a href=\"https://www.npmjs.com/~types\">@types</a> organization are published automatically from <a href=\"https://github.com/DefinitelyTyped/DefinitelyTyped\">DefinitelyTyped</a> using the <a href=\"https://github.com/Microsoft/types-publisher\">types-publisher tool</a>.\nTo get your declarations published as an @types package, please submit a pull request to <a href=\"https://github.com/DefinitelyTyped/DefinitelyTyped\">https://github.com/DefinitelyTyped/DefinitelyTyped</a>.\nYou can find more details in the <a href=\"http://definitelytyped.org/guides/contributing.html\">contribution guidelines page</a>.</p>","headings":[{"value":"Including declarations in your npm package","depth":1},{"value":"Dependencies","depth":2},{"value":"Red flags","depth":2},{"value":"/// <reference path=\"...\" />","depth":3},{"value":"Packaging dependent declarations","depth":3},{"value":"Publish to @types","depth":1}],"frontmatter":{"permalink":"/docs/handbook/declaration-files/publishing.html","title":"Publishing"}}},"pageContext":{"slug":"/docs/handbook/declaration-files/publishing.html","isOldHandbook":true}}}