Deno REPL cannot recognize TypeScript variable declaration

Viewed 276

I installed Deno 1.0.5 on Windows 10, using Chocolatey. I tried to use Typescript in the Deno REPL, but apparently it cannot recognize TypeScript variable declarations if the type is set:

 C:\>deno
 Deno 1.0.5
 exit using ctrl+d or close()
 > let x: number;
 Uncaught SyntaxError: Unexpected token ':'
     at evaluate ($deno$/repl.ts:54:34)
     at Object.replLoop ($deno$/repl.ts:156:13)
 > let x: number = 42;
 Uncaught SyntaxError: Unexpected token ':'
     at evaluate ($deno$/repl.ts:54:34)
     at Object.replLoop ($deno$/repl.ts:156:13)
 > let x = 42;
 undefined
 > x
 42

Do I need to do something special to make Deno CLI support TypeScript?

2 Answers

Deno REPL does not support typescript yet.

See the following old issue: https://github.com/denoland/deno/issues/1158 which is still open.

Comment from Ryan Dahl on a PR that adds TS support:

Feb 24, 2020

Just a bit more context for future researchers: There are many things we can do to improve the REPL without introducing the TS compiler. We should do those things first (e.g. improve inspect, tab completion). Once we're on par with Node's REPL, we can start looking into how to go beyond that by using typescript.

The situation has changed in 2022.

Now deno repl comes with typescript support out of the box:

$ deno
Deno 1.23.0
exit using ctrl+d or close()
> let x : number = 3
undefined
> x.
constructor           toFixed               toString              toLocaleString        __defineSetter__      __lookupGetter__      isPrototypeOf
toExponential         toPrecision           valueOf               __defineGetter__      hasOwnProperty        __lookupSetter__      propertyIsEnumerable

The only thing you need to do is to upgrade your deno executable to a more recent version.

Not sure exactly when this feature landed. Here is the full changelog for reference: https://github.com/denoland/deno/blob/main/Releases.md

Related