<p dir="auto"><strong>What</strong></p>
<p dir="auto">As it stands, there doesn't seem to be a way to generate typings for a file, or files, using Deno. It <em>might</em> be possible with <code class="notranslate">Deno.emit</code>, using the 2nd argument (<code class="notranslate">CompilerOptions</code>), but i haven't checked this and I'm not too confident it can.</p>
<p dir="auto">It also seems like <code class="notranslate">deno types</code> could be expanded upon, ie there's a great opportunity to expand upon this subcommand.</p>
<p dir="auto">But what I propose is for <code class="notranslate">deno types</code> (and ideally a programatic way <strong>as well</strong>) to create the typings for the given file or directory <strong>that outputs to a single file</strong></p>
<p dir="auto"><strong>How</strong></p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="$ deno types src/mod.ts &gt;&gt; dist/mod.d.ts"><pre class="notranslate"><code class="notranslate">$ deno types src/mod.ts &gt;&gt; dist/mod.d.ts
</code></pre></div>
<div class="highlight highlight-source-ts notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="await Deno.emit(&quot;./src/mod.ts&quot;, { typings: true })"><pre class="notranslate"><span class="pl-k">await</span> <span class="pl-smi">Deno</span><span class="pl-kos">.</span><span class="pl-en">emit</span><span class="pl-kos">(</span><span class="pl-s">"./src/mod.ts"</span><span class="pl-kos">,</span> <span class="pl-kos">{</span> <span class="pl-c1">typings</span>: <span class="pl-c1">true</span> <span class="pl-kos">}</span><span class="pl-kos">)</span></pre></div>
<p dir="auto"><strong>Why</strong></p>
<p dir="auto">Well say I have a project that uses typescript. I plan to move over from Node to Deno, but I need typings. It seems impossible to do this with Deno, halting on that projects progress to make the beautiful journey of moving to Deno. This issue. is specifically with emitting a bundled <code class="notranslate">.d.ts</code> file.</p>
<p dir="auto">Whilst I can use <code class="notranslate">Deno.emit(file, { compilerOptions: { declaration: true }})</code>, it still doesn't provide the bundled typings</p>
<p dir="auto"><strong>Example</strong></p>
<p dir="auto">Here is an example, of me wanting to create a single bundled <code class="notranslate">.d.ts</code> file using the <code class="notranslate">emit</code> method, but it not actually providing typings:</p>
<div class="highlight highlight-source-ts notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="// src/mod.ts
export * from &quot;./something.ts&quot;
export * from &quot;./test.ts&quot;"><pre class="notranslate"><span class="pl-c">// src/mod.ts</span>
<span class="pl-k">export</span> <span class="pl-c1">*</span> <span class="pl-k">from</span> <span class="pl-s">"./something.ts"</span>
<span class="pl-k">export</span> <span class="pl-c1">*</span> <span class="pl-k">from</span> <span class="pl-s">"./test.ts"</span></pre></div>
<div class="highlight highlight-source-ts notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="// compile.ts
const stuff = await Deno.emit(&quot;./src/mod.ts&quot;, {
  compilerOptions: {
    &quot;declaration&quot;: true,
    &quot;emitDeclarationOnly&quot;: true,
  }
})
const keys = Object.keys(stuff.files)
const key = keys.find(k =&gt; k.includes(&quot;mod.ts.d.ts&quot;)) as string
console.log(stuff.files[key])"><pre class="notranslate"><span class="pl-c">// compile.ts</span>
<span class="pl-k">const</span> <span class="pl-s1">stuff</span> <span class="pl-c1">=</span> <span class="pl-k">await</span> <span class="pl-smi">Deno</span><span class="pl-kos">.</span><span class="pl-en">emit</span><span class="pl-kos">(</span><span class="pl-s">"./src/mod.ts"</span><span class="pl-kos">,</span> <span class="pl-kos">{</span>
  <span class="pl-c1">compilerOptions</span>: <span class="pl-kos">{</span>
    <span class="pl-s">"declaration"</span>: <span class="pl-c1">true</span><span class="pl-kos">,</span>
    <span class="pl-s">"emitDeclarationOnly"</span>: <span class="pl-c1">true</span><span class="pl-kos">,</span>
  <span class="pl-kos">}</span>
<span class="pl-kos">}</span><span class="pl-kos">)</span>
<span class="pl-k">const</span> <span class="pl-s1">keys</span> <span class="pl-c1">=</span> <span class="pl-smi">Object</span><span class="pl-kos">.</span><span class="pl-en">keys</span><span class="pl-kos">(</span><span class="pl-s1">stuff</span><span class="pl-kos">.</span><span class="pl-c1">files</span><span class="pl-kos">)</span>
<span class="pl-k">const</span> <span class="pl-s1">key</span> <span class="pl-c1">=</span> <span class="pl-s1">keys</span><span class="pl-kos">.</span><span class="pl-en">find</span><span class="pl-kos">(</span><span class="pl-s1">k</span> <span class="pl-c1">=&gt;</span> <span class="pl-s1">k</span><span class="pl-kos">.</span><span class="pl-en">includes</span><span class="pl-kos">(</span><span class="pl-s">"mod.ts.d.ts"</span><span class="pl-kos">)</span><span class="pl-kos">)</span> <span class="pl-k">as</span> <span class="pl-smi">string</span>
<span class="pl-smi">console</span><span class="pl-kos">.</span><span class="pl-en">log</span><span class="pl-kos">(</span><span class="pl-s1">stuff</span><span class="pl-kos">.</span><span class="pl-c1">files</span><span class="pl-kos">[</span><span class="pl-s1">key</span><span class="pl-kos">]</span><span class="pl-kos">)</span></pre></div>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="/// &lt;amd-module name=&quot;file:///.../.../tmp/src/mod.ts&quot; /&gt;
export * from &quot;./something.ts&quot;;
export * from &quot;./test.ts&quot;;"><pre class="notranslate"><code class="notranslate">/// &lt;amd-module name="file:///.../.../tmp/src/mod.ts" /&gt;
export * from "./something.ts";
export * from "./test.ts";
</code></pre></div>
<p dir="auto">As you can see, it doesn't provide any typings</p>
<p dir="auto">With <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="523264961" data-permission-text="Title is private" data-url="https://github.com/denoland/deno/issues/3352" data-hovercard-type="pull_request" data-hovercard-url="/denoland/deno/pull/3352/hovercard" href="https://github.com/denoland/deno/pull/3352">#3352</a>, bundles are going to be a mechanism to distribute "libraries" in Deno.  It is logical that someone might want to use a distribution bundle in another Deno workload (or consume it in other runtimes) and would want to have type safe consumption of those files, therefore we should generate the declarations along with a bundle.</p>
<p dir="auto">Related to <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="453754839" data-permission-text="Title is private" data-url="https://github.com/denoland/deno/issues/2475" data-hovercard-type="issue" data-hovercard-url="/denoland/deno/issues/2475/hovercard" href="https://github.com/denoland/deno/issues/2475">#2475</a>.</p>