Nodeがインストールされている必要がある。
$ npm install -g typescript
$ mkdir HelloWorld
$ cd HelloWord
$ code .
let message : string = "Hello World";
console.log(message);
$ tsc helloworld.ts
出力ファイル(helloworld.js)はhelloworld.tsを同じディレクトリに書かれる。
$ node helaoworld.js
Hello Worla
コンパイルされた出力ファイルの保存先を変更するには outDir をtsconfig.tsファイルに設定し
{
"compileOptions" : {
"target" : "es5",
"module" : "commonjs",
"outDir": "out"
}
}
引数無しでtscを実行する。
$ tsc
引数にファイル名を指定するとtsconfig.jsonは無視される。
sourceMap = true をtsconfig.jsonに設定し
{
"compileOptions" : {
"target" : "es5",
"module" : "commonjs",
"outDir": "out",
"sourceMap": true
}
}
tscを実行してコンパイルを行う。
そしてターゲットファイル(helloworld.js)を選んで、DebugメニューのStart Debuggingを選択する。(デフォルトではデバッガーとしてNode.jsを使用することになる)
Debug Consoleの表示。
/usr/local/bin/node --inspect-brk=5894 out/helloworld.js
Debugger listening on ws://127.0.0.1:5894/3b3993c6-5eaa-4cf9-8aa8-3f3ab28b5223
For help, see: https://nodejs.org/en/docs/inspector
Debugger attached.
Waiting for the debugger to disconnect...
Hello World