Flow 中文全攻略
1.0.0
1.0.0
  • 介紹本書
  • 起步走
    • Flow 簡介
    • 環境安裝
    • 實際使用
  • 型別總覽 ( Type Annotations )
    • Utility Types
    • 型別扮演表達式 ( Type Casting Expressions )
    • 模組化 ( Module Types )
  • 設定
    • .flowconfig
    • .flowconfig [include]
    • .flowconfig [ignore]
    • .flowconfig [untyped]
    • .flowconfig [declarations]
    • .flowconfig [lib]
    • .flowconfig [options]
Powered by GitBook
On this page

Was this helpful?

  1. 起步走

Flow 簡介

強大、可選的型別檢查工具

Flow 是一套 JavaScript 的型別檢查工具,透過型別標註來檢查程式是否依照使用者預期的型別呈現。

// @flow
function square(n: number): number {
    return n * n;
}

square('2'); // 錯誤!

Flow 本身是看得懂我們的 JavaScript 程式的,所以我們也不需要上面那樣辛苦的定義型別,Flow 其實是可以自己「猜出來」的。

可以的話我們應該儘可能的在保持程式碼簡潔、易讀的原則下進行開發。

// @flow
function square(n) {
  return n * n; // 錯誤!
}

square("2");

Flow 是可以漸進式的引入專案的,只要在想要引入的檔案內加入 @flow 註解就好了,其他還沒有要使用的維持原樣就好。在使用上是非常無痛的!

Previous介紹本書Next環境安裝

Last updated 4 years ago

Was this helpful?