LoginSignup
5
0

More than 3 years have passed since last update.

TypeScriptを対話形式で実行する方法

Last updated at Posted at 2019-08-31

環境作成

実行に必要なパッケージがない場合は以下を実行する。

$ npm i -g typescript ts-node

対話形式で実行

$ npx ts-node
>

あとは、対話形式で実行できる。
以下実行例。

> let n: number = 3;
'use strict'
> console.log(n)
3
undefined
> n = null
[eval].ts:3:1 - error TS2322: Type 'null' is not assignable to type 'number'.

tsconfig.jsonのstrictNullChecktrueにしていたので怒られた。

終了

.exitで終了できる。

>.exit

補足

npxコマンドとは、node_modulesフォルダ内のバイナリをパス指定無しで直接実行出来るコマンド。
また、.tsファイルを直接指定する場合は

$ npx ts-node <ファイルのパス>

でいけます。

5
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
0