Often third-party libraries have broken type definitions or have type definitions only compatible with a certain version of Flow. In those cases it may be useful to use type information from the third-party libraries without typechecking their contents.
[declarations] section in a
.flowconfig file tells Flow to parse files
matching the specified regular expressions in declaration mode. In declaration
mode the code is not typechecked. However, the signatures of functions, classes,
etc are extracted and used by the typechecker when checking other code.
Conceptually one can think of declaration mode as if Flow still typechecks the
files but acts as if there is a comment that matches
suppress_comment on every line.
Things to keep in mind:
- Declaration mode should only be used for existing third-party code. You should never use this for code under your control.
- These are OCaml regular expressions.
- These regular expressions match against absolute paths. They probably should
[declarations] section might look like:
[declarations] .*/third_party/.* .*/src/\(foo\|bar\)/.* .*\.decl\.js
[declarations] section will parse in declaration mode:
- Any file or directory under a directory named
- Any file or directory under
- Any file that ends with the extension
Starting with Flow v0.23.0, you may use the
<PROJECT_ROOT> placeholder in
your regular expressions. At runtime, Flow will treat the placeholder as if it
were the absolute path to the project’s root directory. This is useful for
writing regular expressions that are relative rather than absolute.
For example, you can write:
Which would parse in declaration mode any file or directory under the directory
third_party/ within the project root. However, unlike the previous
.*/third_party/.*, it would NOT parse files or directories under
Was this guide helpful? Let us know by sending a message to @flowtype.