I am using flow js for static type checking in my project. 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:
"scripts": {
"flow": "flow",
"flow:check": "flow check ./src/"
}
Now, While running npm run flow:check, I am getting this error.
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.
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; most libraries don't ship/bundle type definitions for Flow (the flow-typed
repo might have them).
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. And the result type of the exported function is a boolean as well.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.