<p dir="auto">It would be great if TypeScript had support for wrapping generated AMD/commonjs module declarations inside a toplevel "external" module, e.g.</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="tsc -d -m commonjs -mname test src/test.ts --outDir out"><pre class="notranslate"><code class="notranslate">tsc -d -m commonjs -mname test src/test.ts --outDir out
</code></pre></div>
<p dir="auto">would result with <code class="notranslate">out/test.d.ts</code> containing</p>
<div class="highlight highlight-source-ts notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="declare module &quot;test&quot; {
  // entire .d.ts file goes here
  export ...
}"><pre class="notranslate"><span class="pl-k">declare</span> module <span class="pl-s">"test"</span> <span class="pl-kos">{</span>
  <span class="pl-c">// entire .d.ts file goes here</span>
  <span class="pl-s1">export</span> ...
<span class="pl-kos">}</span></pre></div>
<p dir="auto">Currently I do this manually with a <a href="https://github.com/spion/tsc-wrap-definition">quick and hacky tool I wrote</a> which seems to work correctly so far for my <a href="https://github.com/doxout/promise-observer">limited needs</a></p>
<p dir="auto">Sorry if this is a duplicate - I'd imagine someone else has asked the same thing - but the absence of a node-facing require'able API has <a href="https://github.com/marijnh/tern/blob/master/lib/typescript.js#L9-L12">other tools like tern</a> requiring files within typescript, and these <a href="https://github.com/marijnh/tern/issues/468" data-hovercard-type="issue" data-hovercard-url="/ternjs/tern/issues/468/hovercard">files predictably move</a> and break those tools.</p>