.flowconfig [untyped]
.flowconfig
文件中的 [untyped]
部分告诉 Flow 不要对与指定正则表达式匹配的文件进行类型检查,而是丢弃类型并将模块视为 any
。
¥The [untyped]
section in a .flowconfig
file tells Flow to not typecheck files
matching the specified regular expressions and instead throw away types and treat modules as any
.
这与 [ignore]
配置部分不同,[ignore]
配置部分会导致匹配文件被模块解析器忽略,这本质上使它们未经类型检查,并且也无法被 import
或 require
解析。当忽略时,必须使用 flow-typed
为每个 import
指定 [libs]
,这可能并不总是理想的。
¥This is different from the [ignore]
config section that causes matching files to be ignored by the module resolver,
which inherently makes them un-typechecked, and also unresolvable by import
or require
.
When ignored, [libs]
must then be specified for each import
using flow-typed
, which may not always be desired.
它也与 [declarations]
部分不同。这也不会对文件内容进行类型检查,但 [declarations]
在检查其他代码时会提取并使用函数、类等的签名。
¥It is also different from the [declarations]
section.
This also does not typecheck the file contents, but [declarations]
does extract and use the signatures of functions, classes, etc, when checking other code.
相反,[untyped]
会导致文件被类型检查器忽略,就好像其中包含 @noflow
一样,将模块解析为 any
类型,但允许模块解析器不忽略它们。Flow 会跳过任何匹配的文件(甚至不会解析,就像其他 @noflow
文件一样!),但仍然可以进行 require()
处理。
¥[untyped]
instead causes a file to be ignored by the typechecker as if it had @noflow
in it,
resolve modules as any
type, but allow them to NOT be ignored by the module resolver.
Any matching file is skipped by Flow (not even parsed, like other @noflow
files!), but can still be require()
'd.
要记住的事情:
¥Things to keep in mind:
这些是 OCaml 正则表达式。
¥These are OCaml regular expressions.
这些正则表达式与绝对路径匹配。他们可能应该从
.*
开始¥These regular expressions match against absolute paths. They probably should start with
.*
[untyped]
部分的示例可能如下所示:
¥An example [untyped]
section might look like:
[untyped]
.*/third_party/.*
.*/src/\(foo\|bar\)/.*
.*\.untyped\.js
这个 [untyped]
部分将解析:
¥This [untyped]
section will parse:
名为
third_party
的目录下的任何文件或目录¥Any file or directory under a directory named
third_party
.*/src/foo
或.*/src/bar
下的任何文件或目录¥Any file or directory under
.*/src/foo
or under.*/src/bar
任何以扩展名
.untyped.js
结尾的文件¥Any file that ends with the extension
.untyped.js
你可以在正则表达式中使用 <PROJECT_ROOT>
占位符。在运行时,Flow 会将占位符视为项目根目录的绝对路径。这对于编写相对而不是绝对的正则表达式很有用。
¥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:
[untyped]
<PROJECT_ROOT>/third_party/.*
它将在声明模式下解析项目根目录中名为 third_party/
的目录下的任何文件或目录。但是,与前面示例的 .*/third_party/.*
不同,它不会解析名为 third_party/
的目录下的文件或目录,例如 src/third_party/
。
¥Which would parse in declaration mode any file or directory under the directory
named third_party/
within the project root. However, unlike the previous
example's .*/third_party/.*
, it would NOT parse files or directories under
directories named third_party/
, like src/third_party/
.