简体   繁体   English

缺少类型注释错误流js

[英]Missing type annotation error flow js

I am using flow js for static type checking in my project. 我在我的项目中使用流js进行静态类型检查。 I am getting errors while checking type. 检查类型时出现错误。

Here are the steps which I followed while setting up flow in project. 这是在项目中设置流程时要遵循的步骤。

npm i flow-bin -SD

Added commands in project.json: 在project.json中添加了命令:

"scripts": {
  "flow": "flow",
  "flow:check": "flow check ./src/"
}

Now, While running npm run flow:check, I am getting this error. 现在,在运行npm run flow:check时,出现此错误。

Missing type annotation for fn.

   6| module.exports = function( ds, schema, fn ) {
                                             ^^

Because Flow needs you to tell it the type signature of that function. 因为Flow需要您告诉它该函数的类型签名。

Now if that's code you don't control (code inside node_modules for example) I suggest to exclude that from being typechecked by Flow; 现在,如果那是您不控制的代码(例如,在node_modules内部的代码),我建议将其排除在Flow的类型检查之外; most libraries don't ship/bundle type definitions for Flow (the flow-typed repo might have them). 大多数库都不提供Flow的/捆绑类型定义( flow-typed仓库可能有它们)。

If that is code that you control (it's part of your app's code), then just add the types. 如果那是您控制的代码(它是应用程序代码的一部分),则只需添加类型。 For example (this are random types, you should replace these with the correct ones): 例如(这是随机类型,应将它们替换为正确的类型):

module.exports = function( ds: string, schema: number, fn: (string) => boolean ): boolean {
    // ...
};

In this example, the ds parameter has to be a string, the schema has to be a number, and the fn parameter has to be a function that accepts a string as the only parameter and will return a boolean when called. 在此示例中, ds参数必须是字符串, schema必须是数字,而fn参数必须是接受字符串作为唯一参数并在被调用时返回布尔值的函数。 And the result type of the exported function is a boolean as well. 导出函数的结果类型也是布尔值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM