Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TypeScript console.log doesn't work

I am trying out TypeScript on Node.js. I have installed it using npm install typescript

When just run tsc:

:~$ tsc Version 1.0.1.0 Syntax: tsc [options] [file ..]

So, I am trying to run simple code: console.log('test'); which is not outputing nothing.

How can I output anyting in console from typescript running on node.js?

like image 535
Andrija Avatar asked May 13 '14 09:05

Andrija


2 Answers

tsc is a compiler not a repl.

You need to write your typescript , compile it with tsc then execute it with nodejs.

like image 113
mpm Avatar answered Oct 24 '22 02:10

mpm


With ts-node, which is a TypeScript execution environment, you can now execute TypeScript with node as you expected from the tsc compiler.

After installing ts-node you can run your example directly as

ts-node -e 'console.log('test')'

or you can run a TypeScript file as:

ts-node script.ts

Please find further details on the ts-node npm page

like image 41
lwallent Avatar answered Oct 24 '22 02:10

lwallent