使用流导出 class 的正确方法?
Correct way to export a class with flow?
将我的 flow-bin 包从 0.142.0 更新到 0.143.1 后,我收到了数百条这样的错误消息(签名验证失败):
我知道此版本的流程使类型优先成为默认模式,但我还是不明白,因为我的所有函数都已正确注释,就像这个简单的 class:
/* @flow */
export class Foo {
bar = (n: number): number => n + 1;
}
我也尝试了 export default Foo
和 module.exports = Foo
但得到了相同的结果。
我在这里错过了什么?
Flow 需要 bar
上的显式类型注释:
export class Foo {
bar: (n: number) => number = n => n + 1;
}
您可以使用 annotate-exports codemod,自动填充一些缺失的注释。
将我的 flow-bin 包从 0.142.0 更新到 0.143.1 后,我收到了数百条这样的错误消息(签名验证失败):
我知道此版本的流程使类型优先成为默认模式,但我还是不明白,因为我的所有函数都已正确注释,就像这个简单的 class:
/* @flow */
export class Foo {
bar = (n: number): number => n + 1;
}
我也尝试了 export default Foo
和 module.exports = Foo
但得到了相同的结果。
我在这里错过了什么?
Flow 需要 bar
上的显式类型注释:
export class Foo {
bar: (n: number) => number = n => n + 1;
}
您可以使用 annotate-exports codemod,自动填充一些缺失的注释。