3

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 2

7

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.

Sign up to request clarification or add additional context in comments.

6 Comments

Interesting... Then why do they advertise Deno as it "supports TypeScript out of the box"? It should not have been given version 1.0 until such a fundamental feature is not implemented.
It supports TS out of the box for scripts. Not for REPL.
I understand that. But the main page (deno.land) lists the features of Deno as a whole, and it says it "supports TypeScript out of the box". It's a major selling point over Node, so moving to 1.0 without supporting TypeScript in the CLI was an unthoughtful move. It makes people disappointed. I won't give up on Deno because of this, but still...
I understand your point but don't agree with it. I see the REPL as a secondary thing, Deno is still in its infancy so I don't see a problem with 1.0.0 not having REPL TS support. There's still a lot of more important things to add/improve before adding it in my opinion.
Sure, but I downloaded it primarily to have an easily accessible TypeScript REPL to test TypeScript code snippets fast :) Thanks for your answer and comments!
|
2

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

4 Comments

This is probably "Type stripping in the REPL": github.com/denoland/deno/pull/10934 -- "It allows TypeScript to be inputted in the REPL and it will transpile it to JS for execution."
It doesn't really make the REPL type-safe. For example, create a function: function add(a: number, b: number): number { return a + b; } I think this function is transpiled immediately to JS because you can call it with string arguments without an error: add("hello", "world") returns "helloworld".
So Deno REPL still doesn't really support TypeScript the way ts-node does, which throws an error in the above case: typestrong.org/ts-node
@kol You are right. They are using --no-check in repl by default: github.com/denoland/deno/issues/13640

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.