Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I ignore some type of errors using flow?

Tags:

flowtype

I just want to either ignore some type of error, or specify a rule on it. in my case it is Cannot resolve name type error. Can I set global variables ? (outside calling code).

like image 697
Curcuma_ Avatar asked Nov 19 '25 20:11

Curcuma_


1 Answers

Yes, you can do this with library definition files. For example:

  1. Create a folder and call it something like definitions
  2. Add this folder under the [libs] section in your .flowconfig
  3. Create a file inside definitions and call it something like globals.js

Inside this globals.js file (or any file inside the definitions folder), you can write declarations. You can see the exact syntax for doing that here: https://flow.org/en/docs/libdefs/creation/

For example, if I wanted to declare that a global age variable exists, I would have this inside my globals.js file:

declare var age: number;

You can also declare complex objects:

declare type Person = {
  name: string,
  age: number
};

declare var person: Person;

If you don't know what type the global variable is, you can set it to any:

declare var weirdThing: any;

If the global variable is coming from a popular 3rd party library, there are probably library definitions that you can install to automatically get type information about it and stop flow errors. Check out flow-typed if you haven't already.


For reference:

Using the example I showed above, your folder structure would look something like:

.
├── .flowconfig
├── definitions
│   └── globals.js
├── package.json
└── src

and your .flowconfig contents would look something like:

[ignore]

[include]

[libs]
definitions

[lints]

[options]

[strict]    
like image 86
Saad Avatar answered Nov 22 '25 17:11

Saad



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!