Software:Flow (type checker)

From HandWiki
Short description: Type-checker and JavaScript superset


Flow
Flow Logo.svg
ParadigmMulti-paradigm: functional, generic, imperative, object-oriented
FamilyJavaScript
Designed byMeta Platforms
DeveloperMeta Platforms
Preview release
v0.226.0
Typing disciplineStructural, nominal
Implementation languageOCaml[1][2]
LicenseMIT License
File formats.flow
Websiteflow.org
Influenced by
JavaScript

Flow is a popular, open-source type-checker for Javascript code which is built and maintained by Meta Platforms.[3][2][4][5] It is used as an alternative for TypeScript and offers stricter analysis, but has a smaller ecosystem.[6] For a while, React recommended Flow as the static type checker to use with JSX, although React no longer provides guidance regarding type-checking following the recent redesign of their website.[7] According to statistics provided by GitHub's dependency graph, Flow is depended on by over 170 thousand different repositories hosted on GitHub alone.[8] In comparison, TypeScript is used in over 15 million repositories.[9]

Features

It supports writing types for libraries in the .flow format, which is somewhat similar to the .d.ts format; however it uses Flow types rather than TypeScript types, which leads to some differences.[10] In addition, it supports checking the types of objects using exact object types, [11] which has been the default in Flow since v0.202.[12] One of TypeScript's major pain points is its lack of support of exact object types.

One of the major benefits of Flow is that it forces the use of explicit type annotations on a module level, which prevents mistakes when deciding SemVer bumps. Additionally, while it is slower,[13][14][15] it is considerably more complete.

History

  • Flow was first announced in 2014, and open-sourced at that time.[3]
  • In February 2015, Flow introduced typecasting and added support for defining types meant to be used outside the current module.[16][17] In comparison, TypeScript added support for import type declarations in early 2020.[18]
  • Later in February 2015, Flow introduced Flow comments, which allows writing type annotations as comments rather than as a syntax extension.[19] They are now one of the most common usages of Flow; in comparison, TypeScript is far more commonly used with its syntax extension.
  • In 2016, Flow added support for Windows.[20]
  • In 2020, a major rework of Flow's architecture was completed, offering up to 6 times faster type-checking.[21][22]
  • In 2021, Facebook announced that Flow would, going forward, be prioritizing internal users of Flow at Facebook, although it would remain open-source.[22][23]
  • In 2023, Flow announced that it had completed the transition to switch Exact Object Types on by default.[12]

References

  1. "facebook/flow: Adds static typing to JavaScript to improve developer productivity and code quality.". https://github.com/facebook/flow. 
  2. 2.0 2.1 "Flow - JavaScript Static Type Checker". 26 August 2021. https://byby.dev/flow. 
  3. 3.0 3.1 Chaudhuri, Avik; Hosmer, Basil; Levi, Gabriel (18 November 2014). "Flow, a new static type checker for JavaScript". https://engineering.fb.com/2014/11/18/web/flow-a-new-static-type-checker-for-javascript/. 
  4. Jackson, Joab. "Facebook's Flow could help JavaScript programmers spot elusive bugs". https://www2.cio.co.nz/article/559947/facebook-flow-could-help-javascript-programmers-spot-elusive-bugs/. 
  5. "ELI5: Flow - Static Type Checker for JavaScript" (in en). https://developers.facebook.com/blog/post/2020/12/14/eli5-flow-static-type-checker-javascript/. 
  6. John, Kapantzakis. "Flow vs TypeScript: Which Is Better Suited For Your Next Project? | Scalable Path" (in en). https://www.scalablepath.com/javascript/flow-vs-typescript. 
  7. "Static Type Checking". https://legacy.reactjs.org/docs/static-type-checking.html. 
  8. "Network Dependents • facebook/flow". https://github.com/facebook/flow/network/dependents. 
  9. "Network Dependents • microsoft/TypeScript". https://github.com/microsoft/TypeScript/network/dependents. 
  10. "Flow: A Static Type Checker for JavaScript | Flow". https://flow.org/en/docs/declarations/. 
  11. "Objects | Flow". https://flow.org/en/docs/types/objects/. 
  12. 12.0 12.1 Zahariev, George (16 February 2023). "Exact object types by default, by default". https://medium.com/flow-type/exact-object-types-by-default-by-default-cc559af6f69. 
  13. Candillon, William (2019-02-07). "Flow vs TypeScript in React — My two cents" (in en). https://levelup.gitconnected.com/flow-vs-typescript-in-react-my-two-cents-d4d0c657d236. 
  14. Brzóska, Bazyli (2024-02-02), niieani/typescript-vs-flowtype, https://github.com/niieani/typescript-vs-flowtype, retrieved 2024-02-14 
  15. "Using Flow in WebStorm | The WebStorm Blog" (in en-US). 2016-11-21. https://blog.jetbrains.com/webstorm/2016/11/using-flow-in-webstorm/. 
  16. Basil, Hosmer (18 February 2015). "Announcing Typecasts". https://flow.org/blog/2015/02/18/Typecasts/. 
  17. Morrison, Jeff (18 February 2015). "Announcing Import Type". https://flow.org/blog/2015/02/18/Import-Types/. 
  18. Rosenwasser, Daniel (20 February 2020). "Announcing TypeScript 3.8". https://devblogs.microsoft.com/typescript/announcing-typescript-3-8/. 
  19. Levi, Gabe (20 February 2015). "Announcing Flow Comments". https://flow.org/blog/2015/02/20/Flow-Comments/. 
  20. Levi, Gabe (1 August 2016). "Windows Support is Here!". https://flow.org/blog/2016/08/01/Windows-Support/. 
  21. Vekris, Panagiotis (18 May 2020). "Types-First: A Scalable New Architecture for Flow". https://medium.com/flow-type/types-first-a-scalable-new-architecture-for-flow-3d8c7ba1d4eb. 
  22. 22.0 22.1 Bruno, Couriol (23 September 2021). "Flow Type Checker No Longer Just JavaScript with Types, Centers of Facebook Needs". https://www.infoq.com/news/2021/09/flow-facebook-not-js-with-types/. 
  23. Vekris, Panagiotis (25 May 2021). "Clarity on Flow's Direction and Open Source Engagement". https://medium.com/flow-type/clarity-on-flows-direction-and-open-source-engagement-e721a4eb4d8b.