flowjs 中的奇怪错误消息 "inconsistent use of library definitions"

Strange error message "inconsistent use of library definitions" in flowjs

我使用 flowjs 有一段时间了,大多数错误信息都很清楚,但现在我得到了这样的信息:

src/framework/uitable/show.js:0
inconsistent use of library definitions
 46:    columns: Array<UiTableConfigColumnType>
                       ^^^^^^^^^^^^^^^^^^^^^^^ object type. This type is incompatible with. See lib: src/framework/uitable/uitable.js.flow:46
 52: type UiTableDataColsType = Array<string>;
                                      ^^^^^^ string. See lib: src/framework/uitable/uitable.js.flow:52

src/framework/uitable/show.js:0
inconsistent use of library definitions
 52: type UiTableDataColsType = Array<string>;
                                      ^^^^^^ string. This type is incompatible with. See lib: src/framework/uitable/uitable.js.flow:52
 46:    columns: Array<UiTableConfigColumnType>
                       ^^^^^^^^^^^^^^^^^^^^^^^ object type. See lib: src/framework/uitable/uitable.js.flow:46

不知道要寻找什么。

定义中的类型似乎没问题,它们之间没有关系,源指向第0行。

我以前从未见过这个错误,我不希望在追踪这个错误的实际来源方面得到任何帮助。

我只是需要一些帮助来理解错误本身的含义以及为什么 flowjs 在第 0 行报告错误 src/framework/uitable/show.js:0

inconsistent use of library definitions 是什么意思?

大多数流错误发生在类型 A 流向类型 B 时。例如,如果您调用一个需要类型为 B 的参数的函数,但您向它传递了类型为 A 的内容。发生这种情况时,Flow 会输出一个错误,说明类型 A 与类型 B.

不兼容

有时候,你有这样的代码

// in file foo.js
libraryCallB(libraryCallA());

在这种情况下,可能 libraryCallA() 的 return 类型与 libraryCallB() 的参数类型不匹配。因此 Flow 会发出类型不兼容的错误。但是,由于两个库调用都是在库中定义的(比如 lib.js),错误消息根本不会提及 foo.js。这并不理想,因为错误可能在 foo.js:0

因此,作为创可贴,我们只是将 foo.js:0 贴在错误的顶部作为提示。这意味着当我们注意到一种库类型流入不兼容的库类型时,我们正在进行类型检查 foo.js

我们一直在努力改进错误消息,因此这些错误应该不会那么普遍。但它们仍然会发生。

你的代码呢?

  • 错误可能在 src/framework/uitable/show.js
  • 中的某处
  • 尝试 flow check --traces 10 它运行正常 flow check,但保存这些 "traces",这有点像 Flow 内部类型检查逻辑的堆栈跟踪。 10 表示打印跟踪深度为 10。除非您熟悉 Flow 的内部结构,否则输出很难理解,但也许它会提到 src/framework/uitable/show.js 中触发错误的位置。
  • 我猜这个错误与 Array<string> 被用作 Array<UiTableConfigColumnType> 或反之亦然有关。