TypeScriptのインストール

パッケージ管理のインストール

npmがまだインストールされていなければ、インストールします。

curl https://npmjs.org/install.sh | sh
 % Total % Received % Xferd Average Speed Time Time Time Current
 Dload Upload Total Spent Left Speed
 100 7882 100 7882 0 0 3833 0 0:00:02 0:00:02 --:--:-- 5004
 tar=/usr/bin/tar
 version:
 bsdtar 2.8.3 - libarchive 2.8.3
 install npm@1.1
 fetching: http://registry.npmjs.org/npm/-/npm-1.1.63.tgz
 0.8.11
 1.1.63
 cleanup prefix=/usr/local
All clean!
> npm@1.1.63 prepublish .
 > npm prune ; rm -rf test/*/*/node_modules ; make -j4 doc
sh: npm: command not found
 sh: make: command not found
 /usr/local/bin/npm -> /usr/local/lib/node_modules/npm/bin/npm-cli.js
 npm@1.1.63 /usr/local/lib/node_modules/npm
 It worked

npmがインストールできました!

TypeScriptをインストール

いよいよnpmでTypeScriptをインストールします。

npm install -g typescript
npm install -g typescript
 npm http GET https://registry.npmjs.org/typescript
 npm http 200 https://registry.npmjs.org/typescript
 npm http GET https://registry.npmjs.org/typescript/-/typescript-0.8.0.tgz
 npm http 200 https://registry.npmjs.org/typescript/-/typescript-0.8.0.tgz
 /usr/local/bin/tsc -> /usr/local/lib/node_modules/typescript/bin/tsc
 typescript@0.8.0 /usr/local/lib/node_modules/typescript
TypeScriptがインストールできました!
tscコマンドでtsコードをコンパイルして、出力を確認します。
tsc greeter.ts
 $ ls /Users/xxx/greeter*
 /Users/xxx/greeter.js /Users/xxx/greeter.ts
 $ cat /Users/noji/greeter.js
 function greeter(person) {
 return "Hello, " + person;
 }
 var user = "Jane User";
 document.body.innerHTML = greeter(user);

Javascriptが吐き出されていました。

コメントを残す

メールアドレスが公開されることはありません。 * が付いている欄は必須項目です

*

次のHTML タグと属性が使えます: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>