How do I deal with d.ts files when publishing my typescript code to npm
<p>I have been following this article:</p>
<p><a href="https://medium.com/@mweststrate/how-to-create-strongly-typed-npm-modules-1e1bda23a7f4#.ja54n8ih7" rel="nofollow noreferrer">How to create strongly-typed npm packages</a></p>
<p>and have been trying to setup my typescript project to publish it to npm.</p>
<p>It all seems to make sense but what is not covered is how to deal with <code>d.ts</code> files.</p>
<p>My project looks somewhat like this:</p>
<pre><code>src
  node
    server.ts
  browser
    client.ts
  common
    contracts.d.ts
</code></pre>
<p>so when I compile this with <code>&quot;declaration&quot;: true</code> and <code>&quot;outDir: &quot;dist&quot;</code> I get:</p>
<pre><code>dist
  node
    server.js
    server.d.ts
  browser
    client.js
    client.d.ts
</code></pre>
<p>both my <code>server.ts</code> file and <code>client.ts</code> files have</p>
<pre><code>import {SomeType} from &quot;../common/contracts&quot;;
</code></pre>
<p>in so when someone else uses this package the typescript compilation will fail as <code>server.d.ts</code> and <code>client.d.ts</code> both still have this import.</p>
<p>Node will run fine though as <code>client.js</code> and <code>server.js</code> do NOT have this import. <code>tsc</code> must remove imports of <code>d.ts</code> files.</p>
<p>What I want to happen is for the <code>contracts.d.ts</code> file to be copied to the dist folder as part of the build. How do I do that as part of the <code>tsc</code> build?</p>
<h2>Current Workaround</h2>
<p>What I am currently doing to get round this is rename my <code>contracts.d.ts</code> to just <code>contracts.ts</code> which means that all required files are present in the dist folder but it does mean that both the client and the server are having to load an empty <code>contracts.js</code> file that only contains</p>
<pre><code>&quot;use strict&quot;;
//# sourceMappingURL=contracts.js.map
</code></pre>