<p dir="auto">At our company we started to use <code class="notranslate">deno</code> as an alternative to <code class="notranslate">make</code> and <code class="notranslate">bash</code> to provide and run build-scripts for multiple projects. Each project contains an <code class="notranslate">aid.ts</code> file in its root which provides a micro-CLI using <a href="https://deno.land/x/docopt@v1.0.1" rel="nofollow">docopt</a>. So far this works nicely.</p>
<p dir="auto">To make the <code class="notranslate">aid.ts</code> files executable from the command line we use this shebang (works on Linux and Mac):</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="#!/bin/sh
&quot;:&quot; //; exec deno run -A --allow-run --unstable --allow-env --allow-write=.local/ --allow-read &quot;$0&quot; &quot;$@&quot;"><pre class="notranslate"><code class="notranslate">#!/bin/sh
":" //; exec deno run -A --allow-run --unstable --allow-env --allow-write=.local/ --allow-read "$0" "$@"
</code></pre></div>
<p dir="auto">A user can access the CLI like this: <code class="notranslate">aid.ts arg1 arg2 ...</code></p>
<p dir="auto">I would love to remove the <code class="notranslate">.ts</code> file extension so that a user can run the tools via <code class="notranslate">aid arg1 arg2...</code>, but as far as I can tell this doesn't work right now. When I remove the extension, deno will interpret the <code class="notranslate">aid</code> file as JavaScript and complain.</p>
<p dir="auto">I think it would be nice if deno offered a way to run such executables without extension. I guess a simple <code class="notranslate">--ts</code> flag for <code class="notranslate">deno run</code> would suffice. What do you think? :-)</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>