LoginSignup
10
11

More than 3 years have passed since last update.

macでTypeScriptの環境を構築したのでメモ

Posted at

macでTypeScriptの開発環境を構築したのでメモ。

node.jsの用意

TypeScriptをインストールするにはnode.jsのnpmを使用するらしい。
node.jsとnpmがインストールされているかを確認。

$ node -v
v8.10.0
$ npm -v
5.6.0

インストールされていた。

バージョンが古いのでアップデートしたい

nをインストール

$ sudo npm install -g n

node.jsを推奨版へアップデート

$ sudo n stable

npmのアップデート

$ sudo npm update -g npm

アップデートされたバージョンの確認

$ node -v
v10.16.3

$ npm -v
6.11.2

TypeScriptをインストール

1 適当な場所にディレクトリを作成

$ mkdir my-typescript-project

2 作成したディレクトリの中で npm initを実行
実行したときに色々聞かれる
package nameversion 以外はそのままエンターでも良さそう。
https://techacademy.jp/magazine/16151

$ cd my-typescript-project
$ npm init

3 ローカルにTypeScriptをインストール

$ npm install --save-dev typescript

4 tsconfig.jsonを作成

$ node_modules/.bin/tsc --init

5 作業ディレクトリ(my-typescript-project)直下にtsファイルを作成

test.ts
export function test() {
    return 'hello wold';
}

6 tsc コマンドを実行

$ node_modules/.bin/tsc

7 my-typescript-project 内に test.js が生成される

test.js
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
function test() {
    return 'hello wold';
}
exports.test = test;

参考

TypeScript チュートリアル
Node.jsとnpmをアップデートする方法

10
11
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
10
11