7. STEP 0. 變更副檔名
All services from your imperative.
*.ts
標準 TypeScript 副檔名
*.d.ts
d is stand for declaration
此為 TypeScript 宣告檔專用的副檔名
用來預先宣告 TypeScript 開發環境中可能會
用到的變數、函數與物件,物件的部分皆以
interface 的方式宣告
7
8. STEP 1. 型別註釋 (Type Annotations)
All services from your imperative.
通用型別
所有型別都是 any 的子型別
基本上 any 就是 JavaScript 可用的任意型別
基本型別 物件型別
number interface
bool module
string class
null 支援 literal 型別
undefined 支援陣列型別
8
9. STEP 1. 型別註釋 (Type Annotations)
All services from your imperative.
標示型別
變數宣告 (全域變數、類別變數、區域變數)
使用 : T 表示法
function 參數支援 optional types 運算子: ?
函式回傳值
支援型別推導
函式傳入參數
9
17. 善用 TypeScript 工具支援
All services from your imperative.
Visual Studio 2012
自動型別檢查 (Static type checking)
隱含強型別推演 (Strong type inference)
移至定義 (Go To Definition) ( F12 )
巡覽至 (Navigate To) ( Ctrl + , )
語法自動完成 / Intellisense ( Ctrl + j )
程式碼重構 (Code refactoring) ( F2 )
下載: TypeScript for Visual Studio 2012 ( v0.8.1.1 )
Monaco (線上版編輯器)
http://www.typescriptlang.org/Playground/
17
18. TypeScript 的工具支援
All services from your imperative.
TypeScript support for Sublime Text
http://www.interoperabilitybridges.com/media/15545
2/typescript_support_for_sublime_text.zip
TypeScript support for Emacs
http://www.interoperabilitybridges.com/media/15544
9/typescript_support_for_emacs.zip
TypeScript support for Vim
http://www.interoperabilitybridges.com/media/15544
6/typescript_support_for_vim.zip
18
25. 聯絡資訊
All services from your imperative.
The Will Will Web
記載著 Will 在網路世界的學習心得與技術分享
http://blog.miniasp.com/
Will 保哥的技術交流中心 (臉書粉絲專頁)
http://www.facebook.com/will.fans
★ ★ ★ Will 保哥的噗浪 ★ ★ ★
http://www.plurk.com/willh/invite
25