<p dir="auto">From <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="367497815" data-permission-text="Title is private" data-url="https://github.com/denoland/deno/issues/929" data-hovercard-type="issue" data-hovercard-url="/denoland/deno/issues/929/hovercard" href="https://github.com/denoland/deno/issues/929">#929</a> and <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="384853190" data-permission-text="Title is private" data-url="https://github.com/denoland/deno/issues/1226" data-hovercard-type="issue" data-hovercard-url="/denoland/deno/issues/1226/hovercard" href="https://github.com/denoland/deno/issues/1226">#1226</a>, I believe that the intended behaviour is that extension-less shebang scripts are seen as TypeScript files, but that does not seems to be the case?</p>
<p dir="auto">Minimal example:</p>
<div class="highlight highlight-source-ts notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="#!/usr/bin/env -S deno run --allow-all
// filename: hi
interface Foo {
  bar: string;
}
console.log(&quot;Hi&quot;);"><pre class="notranslate">#!/usr/bin/env -S deno run --allow-all
<span class="pl-c">// filename: hi</span>
<span class="pl-k">interface</span> <span class="pl-smi">Foo</span> <span class="pl-kos">{</span>
  <span class="pl-c1">bar</span>: <span class="pl-smi">string</span><span class="pl-kos">;</span>
<span class="pl-kos">}</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-s">"Hi"</span><span class="pl-kos">)</span><span class="pl-kos">;</span></pre></div>
<p dir="auto">Running <code class="notranslate">./hi</code> or <code class="notranslate">deno run hi</code> yields <code class="notranslate">error: Unexpected token `interface`.</code></p>
<p dir="auto">I'm trying out deno for scripting (it's been a great experience so far, kudos!).</p>
<p dir="auto">I'd like to be able to create script files without a <code class="notranslate">.ts</code> extension. If I do this, then the following is interpreted as JS and I get a syntax error on the type annotations:</p>
<div class="highlight highlight-source-ts notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="#!/usr/bin/env -S deno run --allow-run --allow-read --allow-write

// code: language=typescript

function hello(name: string) {
  console.log(&quot;Hello,&quot;, name);
}

hello(Deno.args[0]);"><pre class="notranslate">#!/usr/bin/env -S deno run --allow-run --allow-read --allow-write

<span class="pl-c">// code: language=typescript</span>

<span class="pl-k">function</span> <span class="pl-en">hello</span><span class="pl-kos">(</span><span class="pl-s1">name</span>: <span class="pl-smi">string</span><span class="pl-kos">)</span> <span class="pl-kos">{</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-s">"Hello,"</span><span class="pl-kos">,</span> <span class="pl-s1">name</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
<span class="pl-kos">}</span>

<span class="pl-en">hello</span><span class="pl-kos">(</span><span class="pl-smi">Deno</span><span class="pl-kos">.</span><span class="pl-c1">args</span><span class="pl-kos">[</span><span class="pl-c1">0</span><span class="pl-kos">]</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="$  ./myscript 
error: Uncaught SyntaxError: Unexpected token ':'
function hello(name: string) {
                   ^
    at file:///home/joe/tmp/myscript:5:20"><pre class="notranslate"><code class="notranslate">$  ./myscript 
error: Uncaught SyntaxError: Unexpected token ':'
function hello(name: string) {
                   ^
    at file:///home/joe/tmp/myscript:5:20
</code></pre></div>
<p dir="auto">I believe the simplest solution would be to add a CLI flag to force script to be interpreted as typescript.</p>
<p dir="auto">Something like:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="--language=[javascript, typescript]"><pre class="notranslate"><code class="notranslate">--language=[javascript, typescript]
</code></pre></div>
<p dir="auto">so in the above script the shebang becomes:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="#!/usr/bin/env -S deno run --language=typescript --allow-run --allow-read --allow-write"><pre class="notranslate"><code class="notranslate">#!/usr/bin/env -S deno run --language=typescript --allow-run --allow-read --allow-write
</code></pre></div>