LoginSignup
1

More than 5 years have passed since last update.

TypeScript のちょっとした検証をしたい時にぱっと作れる環境

Last updated at Posted at 2017-11-09

TypeScript の検証などを行いたい時にすぐに試せる最小の手順を整理してみました。

検証した際の各バージョンは以下のとおりです。

  • node v8.1.4
  • npm 5.4.2
  • tsc Version 2.6.1

tsc の準備

TypeScript のインストール

npm install -g typescript

tsconfig.json の作成

tsc --init

作成された tsconfig.json の編集は任意
target、module を色々と変えると面白いです。

npm の準備

npm init
# 任意で型定義ファイルをインストールしてください。
# 以下は node.js の型定義ファイルをインストールしています。
# tsconfig.json の types に追加すると、適応されます。
npm install @types/node

tsc でコンパイル

ts ファイルを作成して以下のコマンドを実行する

tsc

最終的にプロジェクト以下はこのようになります。

.
├── index.js // 生成された js ファイル
├── index.ts // 作成した ts ファイル
├── node_modules
├── package-lock.json
├── package.json
└── tsconfig.json

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
What you can do with signing up
1