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).
Yes, you can do this with library definition files. For example:
definitions[libs] section in your .flowconfigdefinitions and call it something like globals.jsInside 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]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With