1分でできるTypeScript実行環境構築

以下のコマンドをターミナルで実行

Node.js推奨版がインストールされていることが前提の手順

mkdir ts; cd ts; npm init -y; npm i -D typescript; npx tsc --init; touch index.html index.ts; echo '<script src="index.js"></script>' > index.html

あとはindex.tsを修正してnpx tscコマンドを実行すればindex.jsが生成される。

// index.ts 修正例
const h: string = 'Hello'
console.log(h)

ターミナルでnode index.jsを実行するかindex.htmlをブラウザで開けばconsole.logの確認などができるようになる。