, 7 tweets, 1 min read
My Authors
Read all threads
今天第 n 次被問到為何如此嫌棄 typescript 以及它的缺點到底有多慘,因此快速整理了一下手邊資料與例子,先講結論:

ts 傾向 completeness 但只做半套因此極不安全,flow 傾向 soundness 並盡量做到最好因此相對較安全。

🤓
用一張圖看 ts 缺點最快,並總結三點如下:

1.unsound 代表無法確保 runtime 不會出錯

2. 不支援 runtime type checking 因此像載入 JSON 資料時無法確保安全性

3. 萬惡的 any 只要用下去程式安全網就消失無蹤,而不幸的它是許多人的最愛

總之採用 ts 的下場就是無止盡的挫折、咒罵與專案延遲😌
同場加映一個趣味 bug,猜猜理應能正常執行的程式為何被 tsc 報錯?😗
但既然這麼多人用所以 ts 總該有些俱體好處吧?

1. 程式碼內可看到型別能有效降低認知負擔

2. 可提供精準自動完成並且重構程式較不易出錯(例如變數更名)

3. 能抓到明顯的型別錯誤(但對 edge case 無能為力)

4. 潮,而且有比沒有好🤡
因此真正重要的關鍵問題是:

1. 團隊與公司是否值得花大量時間與成本來獲取上開好處?

2. 有無其它解決方案效果一樣好但成本低很多?

3. 更簡言之 → 用了 ts 後你真的有爽到嗎?🧐
所以從前端開發的角度來說,眼前有哪些更好的選擇?在此簡單依採行難易度表列如下:

js, flow, elm, reasonML/purescript/haskell, rust

篇幅有限細節就不多說,但簡單講越後面的越好啦😎

最後且聽老納一句勸👇

♥️都要戴套了當然選不會破的否則不如直接中...(喂喂🔞
Missing some Tweet in this thread? You can try to force a refresh.

Keep Current with Jeremy Lu

Profile picture

Stay in touch and get notified when new unrolls are available from this author!

Read all threads

This Thread may be Removed Anytime!

Twitter may remove this content at anytime, convert it as a PDF, save and print for later use!

Try unrolling a thread yourself!

how to unroll video

1) Follow Thread Reader App on Twitter so you can easily mention us!

2) Go to a Twitter thread (series of Tweets by the same owner) and mention us with a keyword "unroll" @threadreaderapp unroll

You can practice here first or read more on our help page!

Follow Us on Twitter!

Did Thread Reader help you today?

Support us! We are indie developers!


This site is made by just two indie developers on a laptop doing marketing, support and development! Read more about the story.

Become a Premium Member ($3.00/month or $30.00/year) and get exclusive features!

Become Premium

Too expensive? Make a small donation by buying us coffee ($5) or help with server cost ($10)

Donate via Paypal Become our Patreon

Thank you for your support!