SlideShare a Scribd company logo
1 of 34
TypeScript ハッカソン
環境構築/Web Serverの準備/ハンズオン
環境構築
TypeScriptをコンパイルするために
VS2012の人
• 以下からダウンロードしてインストール
• http://www.microsoft.com/en-us/download/details.aspx?id=34790
• 「TypeScript for Visual Studio 2012」でググってね!
実施後の追記
どうやらVS2012が入っていなくてもOKらしいです。
Node.jsの人
• Windowsの人
• http://nodejs.org/ からインストーラーをダウンロードしてインス
トール
• MACの人
• 詳しい人だれかお願いします。
• Node.jsが入ってる人
• Node.jsがはいったらこれ
WindowsでNode.jsを入れたくない人
• 実はこんな方法もいけます。
• http://kmaru.hatenablog.com/entry/2013/02/03/195424
Web Server の準備
ハンズオンを実施するために
VS2012が入ってる人
• 特になにもいりません。
• IIS Expressが入っているので次のスライドを参照してください。
• もしくは TypeScript for Visual Studio 2012 を入れるとついてくる
Project Templateでプロジェクトを作ってください。
WindowsでVS2012が入ってない人
• IISExpressがおすすめです。
• WebMatrixが入ってれば入ってるかも
• 以下よりダウンロードできます。
• http://www.microsoft.com/ja-jp/download/details.aspx?id=1038
> "C:Program Files (x86)IIS Expressiisexpress" /path:%~dp0 /port:9090 /clr:v2.0
上のようなバッチファイルを作って実行!
Windows以外の人
• Node.jsで簡単なWebサーバーを作りましょう。
• WindowsでNode.jsが入っている人もこれでもOK
var connect = require("connect");
var server = connect.createServer(
connect.logger(),
connect.static(__dirname)
);
server.listen(3000);
> node server.jsこんなファイル(ここでは
server.js)を作って実行!
あらかじめ用意しました
• 以下をダウンロードして展開
• http://goo.gl/yrTh9
• IISExpressの人
• server.batをダブルクリック!
• Node.jsの人
1. Shellで展開したディレクトリに移
動して
2. npm install
3. npm server.js
• ブラウザで
http://localhost:9090/index.html
にアクセス
ハンズオン
TypeScriptに踏み出すために
ハンズオンを始める前に
• 「Web Serverの準備」でダウンロードしたディレクトリを使い
ます。
• ダウンロードしておいてください。
HTMLを追加しよう
• アプリケーションのルートに「sample.html」を以下の内容で
追加します。
• http://localhost:9090/sample.html にアクセスします。
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<div>
<input type="text" id="message" />
<button type="button" id="exec">Click</button>
</div>
</body>
</html>
JavaScriptを追加しよう
• scriptsフォルダの下に「sample.js」を以下の内容で追加しま
す。
var button = document.getElementById("exec");
var textbox = document.getElementById("message");
button.addEventListener("click", function(){
alert(textbox.value);
}, false);
HTMLからJavaScriptを参照しよう
• sample.htmlのbody要素内の一番下にscript要素を追加します。
• 以下のようになります。
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<div>
<input type="text" id="message" />
<button type="button" id="exec">Click</button>
</div>
<script src="scripts/sample.js"></script>
</body>
</html>
JavaScriptをTypeScriptにしよう
• 「sample.js」のファイル名を「sample.ts」に変更します。
TypeScriptをコンパイルしよう
• コマンドでカレントディレクトリをアプリケーションのルート
ディレクトリに移動します。
• 以下のコマンドを実行します。
• ※失敗します。
> tsc scripts/sample.ts
コンパイルを成功させよう
• 「sample.ts」を以下のように変更します。
var button:any = document.getElementById("exec");
var textbox:any = document.getElementById("message");
button.addEventListener("click", function(){
alert(textbox.value);
}, false);
型をちゃんと指定しよう
• 型をanyとしていた部分をそれぞれの型にキャストします。
var button:HTMLButtonElement =
<HTMLButtonElement>document.getElementById("exec");
var textbox:HTMLInputElement =
<HTMLInputElement>document.getElementById("message");
button.addEventListener("click", function(){
alert(textbox.value);
}, false);
モジュール化しよう
• 「sample.ts」を以下のように変更します。
module App{
var button:HTMLButtonElement =
<HTMLButtonElement>document.getElementById("exec");
var textbox:HTMLInputElement =
<HTMLInputElement>document.getElementById("message");
button.addEventListener("click", function(){
alert(textbox.value);
}, false);
}
クラスを作ろう
• 「message.ts」ファイルを追加して、以下のようにします。
module App{
export class Message{
private _value: String;
constructor(value: String){
this._value = value;
}
}
}
コンパイルしよう
• 以下のコマンドを実行します。
> tsc scripts/*.ts
プロパティを追加しよう
• 「 message.ts」を以下のように変更します。
module App{
export class Message{
private _value: String;
constructor(value: String){
this._value = value;
}
public get value(): String{
return this._value;
}
public set value(v: String){
this._value = v;
}
}
}
コンパイルしよう
• 以下のコマンドを実行します。
• ※失敗します。
> tsc scripts/*.ts
オプションを変更してコンパイルしよう
• tscのオプションを指定します。
> tsc scripts/*.ts –target ES5
ファイルを参照しよう
• 「sample.ts」から「message.ts」を参照します。
• 「sample.ts」を以下のように変更します。
• ※画面は動かなくなります。
/// <reference path="message.ts" />
module App{
var button:HTMLButtonElement =
<HTMLButtonElement>document.getElementById("exec");
var textbox:HTMLInputElement =
<HTMLInputElement>document.getElementById("message");
button.addEventListener("click", function(){
var msg:App.Message = new App.Message(textbox.value);
alert(msg.value.toString());
}, false);
}
HTMLからJavaScriptを参照しよう
• 「sample.html」に「message.js」への参照を追加します。
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<div>
<input type="text" id="message" />
<button type="button" id="exec">Click</button>
</div>
<script src="scripts/message.js"></script>
<script src="scripts/sample.js"></script>
</body>
</html>
jQuery を参照しよう
• 「sample.html」にjQueryの参照を追加します。
• 以下のようなCDNから取ってくると便利です。
• http://ajax.aspnetcdn.com/ajax/jquery/jquery-1.9.1.min.js
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<div>
<input type="text" id="message" />
<button type="button" id="exec">Click</button>
</div>
<script src="http://ajax.aspnetcdn.com/ajax/jquery/jquery-1.9.1.min.js"></script>
<script src="scripts/message.js"></script>
<script src="scripts/sample.js"></script>
</body>
</html>
TypeScriptでjQueryを使ってみよう
• 「sample.ts」を以下のように変更しまて、コンパイルしま
す。
• 失敗します。
/// <reference path="message.ts" />
module App{
var button:any = $("#exec");
var textbox:any = $("#message");
button.on("click", function(){
var msg:App.Message = new App.Message(textbox.val());
alert(msg.value.toString());
});
}
$を解決しよう
• 「sample.ts」を以下のように変更しまて、コンパイルします。
/// <reference path="message.ts" />
declare var $: any;
module App{
var button:any = $("#exec");
var textbox:any = $("#message");
button.on("click", function(){
var msg:App.Message = new App.Message(textbox.val());
alert(msg.value.toString());
});
}
jQueryの型定義を入手しよう
• http://www.tsdpm.com/を開きます。
• jQueryで検索をかけて結果の一番上をクリックします。
• ダイアログの下にあるリンクからダウンロードします。
• ダウンロードした「jquery.d.ts」を「scripts」フォルダの下
に「typings」フォルダを作って格納します。
jQueryの型定義を参照しよう
• 「jquery.d.ts」を参照するために「sample.ts」を以下のよう
に変更してコンパイルします。
/// <reference path="message.ts" />
/// <reference path="typings/jquery.d.ts" />
// declare var $: any; ←削除してもOK
module App{
var button:JQuery = $("#exec");
var textbox:JQuery = $("#message");
button.on("click", function(){
var msg:App.Message = new App.Message(textbox.val());
alert(msg.value.toString());
});
}
Appendix
エディタ
• VS2012
• Expressも対象
• Web Matrix
• Vim
• Emacs
• Sublime Text
• Web Storm
• Flash Develop
• others…

More Related Content

Viewers also liked

ショートカットの勧め
ショートカットの勧めショートカットの勧め
ショートカットの勧めKazuhide Maruyama
 
Grid application テンプレートを紐解く
Grid application テンプレートを紐解くGrid application テンプレートを紐解く
Grid application テンプレートを紐解くKazuhide Maruyama
 
Developerのdeveloperによるdeveloperのためのmetro designの話
Developerのdeveloperによるdeveloperのためのmetro designの話Developerのdeveloperによるdeveloperのためのmetro designの話
Developerのdeveloperによるdeveloperのためのmetro designの話Kazuhide Maruyama
 
Test taking strategies
Test taking strategiesTest taking strategies
Test taking strategiesJohn Woodring
 
Default
DefaultDefault
Defaulthyj163
 
Someone Hacked Into Your Facebook
Someone Hacked Into Your FacebookSomeone Hacked Into Your Facebook
Someone Hacked Into Your FacebookJohn Woodring
 
Type scriptのいいところ
Type scriptのいいところType scriptのいいところ
Type scriptのいいところKazuhide Maruyama
 
Managing the 1 to 1 Classroom
Managing the 1 to 1 ClassroomManaging the 1 to 1 Classroom
Managing the 1 to 1 ClassroomJohn Woodring
 
Teaching in a 1:1 Classroom
Teaching in a 1:1 ClassroomTeaching in a 1:1 Classroom
Teaching in a 1:1 ClassroomJohn Woodring
 
Personal Learning Networks
Personal Learning NetworksPersonal Learning Networks
Personal Learning NetworksJohn Woodring
 
Computer Tech Introduction
Computer Tech IntroductionComputer Tech Introduction
Computer Tech IntroductionJohn Woodring
 
Don’t put that phone away
Don’t put that phone awayDon’t put that phone away
Don’t put that phone awayJohn Woodring
 
Public Health Nursing 1912 1930 Pages 259 265 Trachoma Eradication Through In...
Public Health Nursing 1912 1930 Pages 259 265 Trachoma Eradication Through In...Public Health Nursing 1912 1930 Pages 259 265 Trachoma Eradication Through In...
Public Health Nursing 1912 1930 Pages 259 265 Trachoma Eradication Through In...Karen Shelton, RN
 
Typescriptの中のこと(浅め)
Typescriptの中のこと(浅め)Typescriptの中のこと(浅め)
Typescriptの中のこと(浅め)Kazuhide Maruyama
 

Viewers also liked (18)

ショートカットの勧め
ショートカットの勧めショートカットの勧め
ショートカットの勧め
 
roslyn
roslynroslyn
roslyn
 
What is xaml
What is xamlWhat is xaml
What is xaml
 
Grid application テンプレートを紐解く
Grid application テンプレートを紐解くGrid application テンプレートを紐解く
Grid application テンプレートを紐解く
 
Developerのdeveloperによるdeveloperのためのmetro designの話
Developerのdeveloperによるdeveloperのためのmetro designの話Developerのdeveloperによるdeveloperのためのmetro designの話
Developerのdeveloperによるdeveloperのためのmetro designの話
 
Test taking strategies
Test taking strategiesTest taking strategies
Test taking strategies
 
Default
DefaultDefault
Default
 
Digital portfolios
Digital portfoliosDigital portfolios
Digital portfolios
 
Someone Hacked Into Your Facebook
Someone Hacked Into Your FacebookSomeone Hacked Into Your Facebook
Someone Hacked Into Your Facebook
 
Room Metro 2014-03-01
Room Metro 2014-03-01Room Metro 2014-03-01
Room Metro 2014-03-01
 
Type scriptのいいところ
Type scriptのいいところType scriptのいいところ
Type scriptのいいところ
 
Managing the 1 to 1 Classroom
Managing the 1 to 1 ClassroomManaging the 1 to 1 Classroom
Managing the 1 to 1 Classroom
 
Teaching in a 1:1 Classroom
Teaching in a 1:1 ClassroomTeaching in a 1:1 Classroom
Teaching in a 1:1 Classroom
 
Personal Learning Networks
Personal Learning NetworksPersonal Learning Networks
Personal Learning Networks
 
Computer Tech Introduction
Computer Tech IntroductionComputer Tech Introduction
Computer Tech Introduction
 
Don’t put that phone away
Don’t put that phone awayDon’t put that phone away
Don’t put that phone away
 
Public Health Nursing 1912 1930 Pages 259 265 Trachoma Eradication Through In...
Public Health Nursing 1912 1930 Pages 259 265 Trachoma Eradication Through In...Public Health Nursing 1912 1930 Pages 259 265 Trachoma Eradication Through In...
Public Health Nursing 1912 1930 Pages 259 265 Trachoma Eradication Through In...
 
Typescriptの中のこと(浅め)
Typescriptの中のこと(浅め)Typescriptの中のこと(浅め)
Typescriptの中のこと(浅め)
 

Similar to VSハッカソン TypeScript ハンズオン

13016 n分で作るtype scriptでnodejs
13016 n分で作るtype scriptでnodejs13016 n分で作るtype scriptでnodejs
13016 n分で作るtype scriptでnodejsTakayoshi Tanaka
 
Asp Net Mvc 基礎のキソ
Asp Net Mvc 基礎のキソAsp Net Mvc 基礎のキソ
Asp Net Mvc 基礎のキソYoshitaka Seo
 
はじめての ASP.NET MVC
はじめての ASP.NET MVCはじめての ASP.NET MVC
はじめての ASP.NET MVCjz5 MATSUE
 
Visual Studioで始めるTypeScript開発入門
Visual Studioで始めるTypeScript開発入門Visual Studioで始めるTypeScript開発入門
Visual Studioで始めるTypeScript開発入門Narami Kiyokura
 
はじめてのASP.NET MVC5
はじめてのASP.NET MVC5はじめてのASP.NET MVC5
はじめてのASP.NET MVC5Tomo Mizoe
 
MetroStyleAppsさわってみた わんくま
MetroStyleAppsさわってみた わんくまMetroStyleAppsさわってみた わんくま
MetroStyleAppsさわってみた わんくまc-mitsuba
 
TypeScriptへの入口
TypeScriptへの入口TypeScriptへの入口
TypeScriptへの入口Sunao Tomita
 
Netラボ2012年6月勉強会 マイクロソフトのオープンソース戦略を考える
Netラボ2012年6月勉強会 マイクロソフトのオープンソース戦略を考えるNetラボ2012年6月勉強会 マイクロソフトのオープンソース戦略を考える
Netラボ2012年6月勉強会 マイクロソフトのオープンソース戦略を考えるdavid9142
 
Windows10の展開手法
Windows10の展開手法Windows10の展開手法
Windows10の展開手法NAOKI ABE
 
継続的インテグレーション3分クッキング
継続的インテグレーション3分クッキング継続的インテグレーション3分クッキング
継続的インテグレーション3分クッキングTakayuki Kondou
 
SharePoint Framework Teams タブ開発基礎講座
SharePoint Framework Teams タブ開発基礎講座SharePoint Framework Teams タブ開発基礎講座
SharePoint Framework Teams タブ開発基礎講座Hiroaki Oikawa
 
Introduction for Browser Side MVC
Introduction for Browser Side MVCIntroduction for Browser Side MVC
Introduction for Browser Side MVCRyunosuke SATO
 
ASP.NET MVC 2 ~新機能の紹介~
ASP.NET MVC 2 ~新機能の紹介~ASP.NET MVC 2 ~新機能の紹介~
ASP.NET MVC 2 ~新機能の紹介~Yoshitaka Seo
 
Silverlightアプリをhtml5で表示してみたよ!
Silverlightアプリをhtml5で表示してみたよ!Silverlightアプリをhtml5で表示してみたよ!
Silverlightアプリをhtml5で表示してみたよ!満徳 関
 
[公開用]Netラボ2012年2月勉強会 asp.netmvc4 beta新機能の紹介
[公開用]Netラボ2012年2月勉強会 asp.netmvc4 beta新機能の紹介[公開用]Netラボ2012年2月勉強会 asp.netmvc4 beta新機能の紹介
[公開用]Netラボ2012年2月勉強会 asp.netmvc4 beta新機能の紹介david9142
 
[使い倒し]GitHubのIssueとTFS/VSOのWorkItem連動に挑む(2015/08/26)
[使い倒し]GitHubのIssueとTFS/VSOのWorkItem連動に挑む(2015/08/26)[使い倒し]GitHubのIssueとTFS/VSOのWorkItem連動に挑む(2015/08/26)
[使い倒し]GitHubのIssueとTFS/VSOのWorkItem連動に挑む(2015/08/26)Masanori Ishigami
 

Similar to VSハッカソン TypeScript ハンズオン (20)

13016 n分で作るtype scriptでnodejs
13016 n分で作るtype scriptでnodejs13016 n分で作るtype scriptでnodejs
13016 n分で作るtype scriptでnodejs
 
Asp Net Mvc 基礎のキソ
Asp Net Mvc 基礎のキソAsp Net Mvc 基礎のキソ
Asp Net Mvc 基礎のキソ
 
はじめての ASP.NET MVC
はじめての ASP.NET MVCはじめての ASP.NET MVC
はじめての ASP.NET MVC
 
Visual Studioで始めるTypeScript開発入門
Visual Studioで始めるTypeScript開発入門Visual Studioで始めるTypeScript開発入門
Visual Studioで始めるTypeScript開発入門
 
はじめてのASP.NET MVC5
はじめてのASP.NET MVC5はじめてのASP.NET MVC5
はじめてのASP.NET MVC5
 
MetroStyleAppsさわってみた わんくま
MetroStyleAppsさわってみた わんくまMetroStyleAppsさわってみた わんくま
MetroStyleAppsさわってみた わんくま
 
20060419
2006041920060419
20060419
 
20120118 titanium
20120118 titanium20120118 titanium
20120118 titanium
 
TypeScriptへの入口
TypeScriptへの入口TypeScriptへの入口
TypeScriptへの入口
 
Netラボ2012年6月勉強会 マイクロソフトのオープンソース戦略を考える
Netラボ2012年6月勉強会 マイクロソフトのオープンソース戦略を考えるNetラボ2012年6月勉強会 マイクロソフトのオープンソース戦略を考える
Netラボ2012年6月勉強会 マイクロソフトのオープンソース戦略を考える
 
Ext.direct
Ext.directExt.direct
Ext.direct
 
Windows10の展開手法
Windows10の展開手法Windows10の展開手法
Windows10の展開手法
 
継続的インテグレーション3分クッキング
継続的インテグレーション3分クッキング継続的インテグレーション3分クッキング
継続的インテグレーション3分クッキング
 
SharePoint Framework Teams タブ開発基礎講座
SharePoint Framework Teams タブ開発基礎講座SharePoint Framework Teams タブ開発基礎講座
SharePoint Framework Teams タブ開発基礎講座
 
Introduction for Browser Side MVC
Introduction for Browser Side MVCIntroduction for Browser Side MVC
Introduction for Browser Side MVC
 
ASP.NET MVC 2 ~新機能の紹介~
ASP.NET MVC 2 ~新機能の紹介~ASP.NET MVC 2 ~新機能の紹介~
ASP.NET MVC 2 ~新機能の紹介~
 
ScalaMatsuri 2016
ScalaMatsuri 2016ScalaMatsuri 2016
ScalaMatsuri 2016
 
Silverlightアプリをhtml5で表示してみたよ!
Silverlightアプリをhtml5で表示してみたよ!Silverlightアプリをhtml5で表示してみたよ!
Silverlightアプリをhtml5で表示してみたよ!
 
[公開用]Netラボ2012年2月勉強会 asp.netmvc4 beta新機能の紹介
[公開用]Netラボ2012年2月勉強会 asp.netmvc4 beta新機能の紹介[公開用]Netラボ2012年2月勉強会 asp.netmvc4 beta新機能の紹介
[公開用]Netラボ2012年2月勉強会 asp.netmvc4 beta新機能の紹介
 
[使い倒し]GitHubのIssueとTFS/VSOのWorkItem連動に挑む(2015/08/26)
[使い倒し]GitHubのIssueとTFS/VSOのWorkItem連動に挑む(2015/08/26)[使い倒し]GitHubのIssueとTFS/VSOのWorkItem連動に挑む(2015/08/26)
[使い倒し]GitHubのIssueとTFS/VSOのWorkItem連動に挑む(2015/08/26)
 

VSハッカソン TypeScript ハンズオン