Skip to content

Commit af65cd9

Browse files
committed
Updates
0 parents  commit af65cd9

File tree

788 files changed

+470970
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

788 files changed

+470970
-0
lines changed

404.html

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<!doctype html>
2+
<html lang="en" dir="ltr" class="plugin-native plugin-id-default">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="generator" content="Docusaurus v2.4.1">
6+
<title data-rh="true">Page Not Found | Flow</title><meta data-rh="true" name="viewport" content="width=device-width,initial-scale=1"><meta data-rh="true" name="twitter:card" content="summary_large_image"><meta data-rh="true" property="og:url" content="https://flow.org/404.html"><meta data-rh="true" name="docusaurus_locale" content="en"><meta data-rh="true" name="docusaurus_tag" content="default"><meta data-rh="true" name="docsearch:language" content="en"><meta data-rh="true" name="docsearch:docusaurus_tag" content="default"><meta data-rh="true" property="og:title" content="Page Not Found | Flow"><link data-rh="true" rel="icon" href="/img/favicon.png"><link data-rh="true" rel="canonical" href="https://flow.org/404.html"><link data-rh="true" rel="alternate" href="https://flow.org/404.html" hreflang="en"><link data-rh="true" rel="alternate" href="https://flow.org/404.html" hreflang="x-default"><link data-rh="true" rel="preconnect" href="https://P6T3E8XPGT-dsn.algolia.net" crossorigin="anonymous"><link rel="alternate" type="application/rss+xml" href="/blog/rss.xml" title="Flow RSS Feed">
7+
<link rel="alternate" type="application/atom+xml" href="/blog/atom.xml" title="Flow Atom Feed">
8+
9+
<link rel="preconnect" href="https://www.google-analytics.com">
10+
<script>window.ga=window.ga||function(){(ga.q=ga.q||[]).push(arguments)},ga.l=+new Date,ga("create","UA-49208336-4","auto"),ga("set","anonymizeIp",!0),ga("send","pageview")</script>
11+
<script async src="https://www.google-analytics.com/analytics.js"></script>
12+
13+
14+
<link rel="search" type="application/opensearchdescription+xml" title="Flow" href="/opensearch.xml"><link rel="stylesheet" href="/assets/css/styles.aa18815f.css">
15+
<link rel="preload" href="/assets/js/runtime~main.b1727f31.js" as="script">
16+
<link rel="preload" href="/assets/js/main.77ecfc36.js" as="script">
17+
</head>
18+
<body class="navigation-with-keyboard">
19+
<script>!function(){function t(t){document.documentElement.setAttribute("data-theme",t)}var e=function(){var t=null;try{t=new URLSearchParams(window.location.search).get("docusaurus-theme")}catch(t){}return t}()||function(){var t=null;try{t=localStorage.getItem("theme")}catch(t){}return t}();t(null!==e?e:"light")}()</script>
20+
21+
<div style="display: none; text-align: center; background-color: white; color: black;" id="internaldocs-banner"></div><div id="__docusaurus">
22+
<div role="region" aria-label="Skip to main content"><a class="skipToContent_fXgn" href="#__docusaurus_skipToContent_fallback">Skip to main content</a></div><nav aria-label="Main" class="navbar navbar--fixed-top"><div class="navbar__inner"><div class="navbar__items"><button aria-label="Toggle navigation bar" aria-expanded="false" class="navbar__toggle clean-btn" type="button"><svg width="30" height="30" viewBox="0 0 30 30" aria-hidden="true"><path stroke="currentColor" stroke-linecap="round" stroke-miterlimit="10" stroke-width="2" d="M4 7h22M4 15h22M4 23h22"></path></svg></button><a class="navbar__brand" href="/"><div class="navbar__logo"><img src="/img/logo.svg" alt="My Facebook Project Logo" class="themedImage_ToTc themedImage--light_HNdA"><img src="/img/logo.svg" alt="My Facebook Project Logo" class="themedImage_ToTc themedImage--dark_i4oU"></div></a><a class="navbar__item navbar__link" href="/en/docs/getting-started/">Getting Started</a><a class="navbar__item navbar__link" href="/en/docs/">Docs</a><a class="navbar__item navbar__link" href="/try/">Try</a><a class="navbar__item navbar__link" href="/blog/">Blog</a></div><div class="navbar__items navbar__items--right"><a href="https://twitter.com/flowtype" target="_blank" rel="noopener noreferrer" class="navbar__item navbar__link navbar__icon twitter__link" aria-label="Twitter"></a><a href="http://stackoverflow.com/questions/tagged/flowtype" target="_blank" rel="noopener noreferrer" class="navbar__item navbar__link navbar__icon stackoverflow__link" aria-label="Stack Overflow"></a><a href="https://github.com/facebook/flow" target="_blank" rel="noopener noreferrer" class="navbar__item navbar__link navbar__icon github__link" aria-label="GitHub"></a><div class="searchBox_ZlJk"><button type="button" class="DocSearch DocSearch-Button" aria-label="Search"><span class="DocSearch-Button-Container"><svg width="20" height="20" class="DocSearch-Search-Icon" viewBox="0 0 20 20"><path d="M14.386 14.386l4.0877 4.0877-4.0877-4.0877c-2.9418 2.9419-7.7115 2.9419-10.6533 0-2.9419-2.9418-2.9419-7.7115 0-10.6533 2.9418-2.9419 7.7115-2.9419 10.6533 0 2.9419 2.9418 2.9419 7.7115 0 10.6533z" stroke="currentColor" fill="none" fill-rule="evenodd" stroke-linecap="round" stroke-linejoin="round"></path></svg><span class="DocSearch-Button-Placeholder">Search</span></span><span class="DocSearch-Button-Keys"></span></button></div></div></div><div role="presentation" class="navbar-sidebar__backdrop"></div></nav><div id="__docusaurus_skipToContent_fallback" class="main-wrapper mainWrapper_z2l0"><main class="container margin-vert--xl"><div class="row"><div class="col col--6 col--offset-3"><h1 class="hero__title">Page Not Found</h1><p>We could not find what you were looking for.</p><p>Please contact the owner of the site that linked you to the original URL and let them know their link is broken.</p></div></div></main></div><footer class="footer footer--dark"><div class="container container-fluid"><div class="row footer__links"><div class="col footer__col"><div class="footer__title">Learn</div><ul class="footer__items clean-list"><li class="footer__item"><a class="footer__link-item" href="/en/docs/getting-started/">Getting Started</a></li></ul></div><div class="col footer__col"><div class="footer__title">Community</div><ul class="footer__items clean-list"><li class="footer__item"><a href="https://twitter.com/flowtype" target="_blank" rel="noopener noreferrer" class="footer__link-item">Twitter<svg width="13.5" height="13.5" aria-hidden="true" viewBox="0 0 24 24" class="iconExternalLink_nPIU"><path fill="currentColor" d="M21 13v10h-21v-19h12v2h-10v15h17v-8h2zm3-12h-10.988l4.035 4-6.977 7.07 2.828 2.828 6.977-7.07 4.125 4.172v-11z"></path></svg></a></li><li class="footer__item"><a href="https://discordapp.com/invite/8ezwRUK" target="_blank" rel="noopener noreferrer" class="footer__link-item">Discord<svg width="13.5" height="13.5" aria-hidden="true" viewBox="0 0 24 24" class="iconExternalLink_nPIU"><path fill="currentColor" d="M21 13v10h-21v-19h12v2h-10v15h17v-8h2zm3-12h-10.988l4.035 4-6.977 7.07 2.828 2.828 6.977-7.07 4.125 4.172v-11z"></path></svg></a></li></ul></div><div class="col footer__col"><div class="footer__title">More</div><ul class="footer__items clean-list"><li class="footer__item"><a href="https://medium.com/flow-type" target="_blank" rel="noopener noreferrer" class="footer__link-item">Medium</a></li><li class="footer__item"><a href="https://github.com/facebook/flow" target="_blank" rel="noopener noreferrer" class="footer__link-item">GitHub<svg width="13.5" height="13.5" aria-hidden="true" viewBox="0 0 24 24" class="iconExternalLink_nPIU"><path fill="currentColor" d="M21 13v10h-21v-19h12v2h-10v15h17v-8h2zm3-12h-10.988l4.035 4-6.977 7.07 2.828 2.828 6.977-7.07 4.125 4.172v-11z"></path></svg></a></li></ul></div><div class="col footer__col"><div class="footer__title">Legal</div><ul class="footer__items clean-list"><li class="footer__item"><a href="https://opensource.facebook.com/legal/privacy/" target="_blank" rel="noopener noreferrer" class="footer__link-item">Privacy<svg width="13.5" height="13.5" aria-hidden="true" viewBox="0 0 24 24" class="iconExternalLink_nPIU"><path fill="currentColor" d="M21 13v10h-21v-19h12v2h-10v15h17v-8h2zm3-12h-10.988l4.035 4-6.977 7.07 2.828 2.828 6.977-7.07 4.125 4.172v-11z"></path></svg></a></li><li class="footer__item"><a href="https://opensource.facebook.com/legal/terms/" target="_blank" rel="noopener noreferrer" class="footer__link-item">Terms<svg width="13.5" height="13.5" aria-hidden="true" viewBox="0 0 24 24" class="iconExternalLink_nPIU"><path fill="currentColor" d="M21 13v10h-21v-19h12v2h-10v15h17v-8h2zm3-12h-10.988l4.035 4-6.977 7.07 2.828 2.828 6.977-7.07 4.125 4.172v-11z"></path></svg></a></li><li class="footer__item"><a href="https://opensource.facebook.com/legal/data-policy/" target="_blank" rel="noopener noreferrer" class="footer__link-item">Data Policy<svg width="13.5" height="13.5" aria-hidden="true" viewBox="0 0 24 24" class="iconExternalLink_nPIU"><path fill="currentColor" d="M21 13v10h-21v-19h12v2h-10v15h17v-8h2zm3-12h-10.988l4.035 4-6.977 7.07 2.828 2.828 6.977-7.07 4.125 4.172v-11z"></path></svg></a></li><li class="footer__item"><a href="https://opensource.facebook.com/legal/cookie-policy/" target="_blank" rel="noopener noreferrer" class="footer__link-item">Cookie Policy<svg width="13.5" height="13.5" aria-hidden="true" viewBox="0 0 24 24" class="iconExternalLink_nPIU"><path fill="currentColor" d="M21 13v10h-21v-19h12v2h-10v15h17v-8h2zm3-12h-10.988l4.035 4-6.977 7.07 2.828 2.828 6.977-7.07 4.125 4.172v-11z"></path></svg></a></li></ul></div></div><div class="footer__bottom text--center"><div class="margin-bottom--sm"><a href="https://opensource.facebook.com" rel="noopener noreferrer" class="footerLogoLink_BH7S"><img src="/img/oss_logo.png" alt="Facebook Open Source Logo" class="themedImage_ToTc themedImage--light_HNdA footer__logo"><img src="/img/oss_logo.png" alt="Facebook Open Source Logo" class="themedImage_ToTc themedImage--dark_i4oU footer__logo"></a></div><div class="footer__copyright">Copyright © 2025 Meta Platforms, Inc. Built with Docusaurus.</div></div></div></footer></div>
23+
<script src="/assets/js/runtime~main.b1727f31.js"></script>
24+
<script src="/assets/js/main.77ecfc36.js"></script>
25+
</body>
26+
</html>

CNAME

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
flow.org

_src/cli/annotate-exports.md

+80
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
---
2+
title: Flow Annotate-Exports
3+
slug: /cli/annotate-exports
4+
---
5+
6+
Upgrading to [Types-First](../../lang/types-first) mode may require a substantial
7+
number of type annotations at module boundaries. To help with the process of
8+
upgrading large codebases, we are providing a codemod command, whose goal is to
9+
fill in these missing annotations. This command is included in the Flow binary
10+
in versions `>= 0.125`.
11+
12+
> Note: As of version 0.134, types-first is the default mode. If you are using a
13+
version `>=0.134`, make sure you set `types_first=false` in your .flowconfig while
14+
running this codemod.
15+
16+
This command uses types that Flow infers, to fill in positions that would otherwise
17+
raise *signature-verification* failures. It will include the necessary type import
18+
statements, as long as the respective types are exported from their defining modules.
19+
20+
It is designed for use on multiple files at once, rather than one file at a time.
21+
For this reason it doesn't connect to an existing Flow server, but rather starts
22+
a checking process of its own.
23+
24+
As is typical with such mechanized approaches, it comes with a few caveats:
25+
26+
1. It won’t be able to fill in every required type annotation. Some cases will
27+
require manual effort.
28+
2. Inserted annotations may cause new flow errors, since it’s not always possible
29+
to match inferred type with types that can be written as annotations.
30+
3. File formatting may be affected. If a code formatter (e.g. prettier) is used,
31+
it is recommended that you run it after the codemod has finished running.
32+
33+
34+
### How to apply the codemod {#toc-how-to-apply-the-codemod}
35+
36+
A typical way to invoke this command is
37+
38+
```
39+
flow codemod annotate-exports \
40+
--write \
41+
--repeat \
42+
--log-level info \
43+
/path/to/folder \
44+
2> out.log
45+
```
46+
47+
This command will transform files under `/path/to/folder`. This does not need to
48+
be the root directory (the one containing `.flowconfig`).
49+
50+
It uses the following flags:
51+
* `--write` will update files that require annotations under `/path/to/folder`
52+
in-place. Without this flag the resulting files will be printed on the command line.
53+
54+
* `--repeat` ensures that the transformation will be applied until no more files
55+
change. This mode is necessary here, because each new type the codemod adds may
56+
require new locations to be annotated.
57+
58+
* `--log-level info` outputs useful debugging information in the standard error stream.
59+
This option might lead to verbose output, so we're redirecting the error output
60+
to a log file `out.log`.
61+
62+
Another convenient way to provide the input is by passing the flag
63+
```
64+
--input-file file.txt
65+
```
66+
where `file.txt` contains a specific list of files to be transformed.
67+
68+
### Codemod output {#toc-codemod-output}
69+
70+
After each iteration of the codemod, a summary will be printed on the CLI. This
71+
summary includes statistical information about the number of annotations that were
72+
added, and how many locations were skipped. It also prints counts for various kinds
73+
of errors that were encountered. These can be matched to the errors printed in the
74+
logs.
75+
76+
A common error case is when a type `A`, defined in a file `a.js`, but not exported,
77+
is inferred in file `b.js`. The codemod will skip adding this annotation and report
78+
an error in the logs. The fix this case, you can export `A` in `a.js`. Note that
79+
it is not necessary to manually import `A` in `b.js`. The codemod will do this
80+
automatically.

_src/cli/coverage.md

+128
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
---
2+
title: Flow Coverage
3+
slug: /cli/coverage
4+
---
5+
The coverage command provides a metric of the amount of checking that Flow has
6+
performed on each part of your code. A program with high Flow coverage should
7+
increase your confidence that Flow has detected any potential runtime errors.
8+
9+
The determining factor for this is the presence of [`any`](../../types/any/) in the
10+
inferred type of each expression. An expression whose inferred type is `any` is
11+
considered *uncovered*, otherwise it is considered *covered*.
12+
13+
To see why this metric was chosen for determining Flow's effectiveness, consider
14+
the example
15+
16+
```js flow-check
17+
const one: any = 1;
18+
one();
19+
```
20+
21+
This code leads to a runtime type error, since we are attempting to perform a call
22+
on a number. Flow, however, does not flag an error here, because we have annotated
23+
variable `one` as `any`. Flow's checking is effectively turned off whenever `any`
24+
is involved, so it will silently allow the call. The use of this *unsafe* type has
25+
rendered the type checker ineffective, and the coverage metric is here to surface
26+
this, by reporting all instances of `one` as uncovered.
27+
28+
## Design Space {#toc-design-space}
29+
30+
**Which types should be "covered"?**
31+
32+
What was described above is a rather coarse grained way to determine coverage. One
33+
could imagine a criterion that flags expressions as uncovered if *any* part of their
34+
type includes `any`, for example `Array<any>`. While there is value in a metric like
35+
this, the "uncovered" part of the type will typically be uncovered through various
36+
operations on values of this type. For example, in the code
37+
38+
```js flow-check
39+
declare const arr: Array<any>;
40+
arr.forEach(x => {});
41+
```
42+
43+
the parameter `x` will be flagged as uncovered. Also, in practice, a strict criterion
44+
like this would be too noisy and rather expensive to compute on the fly.
45+
46+
**Union types**
47+
48+
An exception to this principle are union types: the type `number | any` is considered
49+
*uncovered*, even though technically `any` is not the top-level constructor.
50+
Unions merely encode an option among *a set of* other types. In that sense we are
51+
conservatively viewing an expression as uncovered, when at least one possible type
52+
of that expression causes limited checking. For example, in the code
53+
54+
```js flow-check
55+
let x: number | any = 1;
56+
x = "a";
57+
```
58+
59+
Flow will let you assign anything to `x`, which reduces confidence in the use
60+
of `x` as a number. Thus `x` is considered uncovered.
61+
62+
**The empty type**
63+
64+
An interesting type from a coverage perspective is the [`empty`](../../types/empty) type.
65+
This type roughly corresponds to *dead code*. As such checking around expressions with
66+
type `empty` is more relaxed, but for a good reason: this code will not be executed at
67+
runtime. Since it is a common practice to clean up such code, Flow coverage will
68+
also report code whose type is inferred to be `empty`, but distinguishes it from
69+
the case of `any`.
70+
71+
72+
## Command Line Use {#toc-command-line-use}
73+
74+
To find out the coverage of a file foo.js with the following contents
75+
76+
```js flow-check
77+
function add(one: any, two: any): number {
78+
return one + two;
79+
}
80+
81+
add(1, 2);
82+
```
83+
84+
you can issue the following command
85+
86+
```
87+
$ flow coverage file.js
88+
Covered: 50.00% (5 of 10 expressions)
89+
```
90+
This output means that 5 out of the 10 nodes of this program were inferred to have type
91+
`any`. To see exactly which parts are uncovered you can also pass one of the following
92+
flags:
93+
* `--color`: This will print foo.js on the terminal with the uncovered locations in
94+
red color. E.g. `flow coverage --color file.js`
95+
* `--json`: This will list out all location spans that are uncovered under
96+
the tag `"uncovered_locs"`. E.g. `flow coverage --json file.js`
97+
98+
Finally, as an example of dead code, consider the code:
99+
100+
```js flow-check
101+
function f(x: 'a' | 'b') {
102+
if (x === 'a') {
103+
// ...
104+
} else if (x === 'b') {
105+
// ...
106+
} else {
107+
x;
108+
}
109+
}
110+
```
111+
112+
The final `else` clause should never be reached, as we've already checked for both members of the union.
113+
Because of this, `x` is inferred to have the type `empty` in that branch.
114+
115+
In the colored version of this command, these parts appear in blue color,
116+
and in the JSON version they are under the field `"empty_locs"`.
117+
118+
**Use on multiple files**
119+
120+
If you want to check coverage of multiple files at once, Flow offers the
121+
`batch-coverage` command:
122+
```
123+
$ flow batch-coverage dir/
124+
```
125+
will report coverage statistics for each file under `dir/`, as well as aggregate
126+
results.
127+
128+
Note that `batch-coverage` requires a non-lazy Flow server.

0 commit comments

Comments
 (0)