This document discusses replacing TypeScript with Dart for a new product. In 2016, TypeScript was initially chosen for its static typing and classes, but circular reference issues arose. Dart was then considered but had performance and ecosystem issues in version 1. Dart version 2 improved performance but dropped some features and Dart2JS stacktraces remained difficult to read. Ultimately Dart was chosen over continuing to use TypeScript due to the effort required to fix existing code issues.
10. 選邊站? (不是 Blue vs Green)
1. Face it
• Use tools to check (unreliable)
• Lazy import modules (very easy to forget)
2. Migrate to another Lang. (Dart) but …
• 1450+ ts files already
• 350,870 lines of code (87%, 28~30w lines)
• (3~4 工人智慧)
12. Dart 1 - 2016 Nov.
• Pros.
• Types
• Number, String, Boolean, List, Map, and so on.
• Classes
• No public, protected, and private
• (but If an identifier starts with an underscore (_), it’s private to its library)
• Interfaces (implicit)
• Generics
• Asynchronous functions
• async and await
• Dartium (without compiling to JS)
• Transforms (like AOP)
Types: Optional static type notation
也支援Union types,可以混搭型別
Namespaces and Modules: 好切割你的程式碼
Generics: 一樣也有泛型
TypeScript – tsconfig.json跟TS相關的設定
Typings – 如果用到的nodejs library沒有ts的typings, 還要自己寫 (不同的寫法可能會造成 ES6 在imports時語法會有問題)
SystemJS: 用來動態載入modules,當年TypeScript好像比較推薦這個。
Webpack: 壓縮打包JS需要用的,大家比較熟悉
ts-loader: 我們客制化了一個自己的,為了可以載入submodule 而做的。(當年ts會看不到submodule, 所以做個mapping到node_modules下去騙它)
babel: 要支援舊版browser就需要用到它。
ts-node – (wrong line number when run with Webstorm)
Gulp – task runner,用來跑整個產品出貨,測試,產生文件需要的任務,有寫過Java的人,它就像Java的Ant一樣的工具。
Mocha - run test cases
有沒有像在7-11打工的工讀生一樣呢? (樣樣都要學)
產品開發幾個月後 就發現一個不好解的問題,也許是做Library or Component而且modules又切很細的才會遇到的問題,一般只拿來寫應用程式可能不會遇到。
像 a module 用到 b module, 又用到 c module ,然後直回到a module,
看起來很好避開,但如果你的modules是很多,而且,你不知道你的使用者會如何呼叫你的程式,
這樣,你的排列組合就會很多種,因為JS是interpreter 的程式語言,跟你怎麼寫的順序有關係。 (當然現在也有很多技術可以compiles the code on the fly 像v8)
下面這張圖比較可以說明現狀。