Reputation: 22797
I've googled many sites but cannot found a tutorial that actually works for react-native + flow type.
There was flow installation guide from [email protected] document, but it's gone in [email protected].
However, it comes up again in Running Tests and Contributing, I tested to run npm run flow
but not working, and yet it doesn't say how to make it works. It's possibly been a missing part inside of react-native documentation.
What I need is to run flow
correctly with react-native. Auto-check flow
every time I reload the page with ⌘R
would be the best.
Upvotes: 10
Views: 6137
Reputation: 373
I just finished covering half of our project by flow and we use RN 0.44.0.
The tricky part is: do you also want to know errors inside node_modules, someone says those errors are helpful.
Anyway, I disable the error in node_modules, and here is my .flowconfig:
[ignore]
<PROJECT_ROOT>/node_modules/.*
<PROJECT_ROOT>/flowLibs.js
.....
[include]
[libs]
./flowLibs.js
.....
[lints]
[options]
You should install flow first if you not setup correctly,
npm install --save-dev flow-bin
and also run this in you project root after install:
npm run flow init
If npm run flow init
does not work, just add "flow": "flow"
in npm scripts.
After init, put my .flowconfig
in your project .flowconfig
file.
Then create a js file flowLibs.js
and if npm run flow check
cause your any error like Module_Name. Required module not found
Write down code in flowLibs.js
:
declare module 'Module_Name' { declare var exports: any; };
After that, you should be good to go with you project now.
BTW, don't forget add //@flow
on the top of the file which you want to check type.
Upvotes: 7
Reputation: 22797
I found flowtype is built in with [email protected]+.
For react-native document, I think they should at least tell flowtype is already built in. And for the rest document ex: Testing Your Changes@flow, it won't work without flow-bin
, they should mention that too.
To make flowtype of best use, I use it with Visual Studio Code.
Steps:
flow-bin
globally, by npm i flow-bin -g
.
Make sure your terminal is responsive to command flow
."javascript.validate.enable": false
, to disable default javascript validation, so flow validation can take place.
To access vscode preference, ALT+F,P,S
for windows, ⌘+,
for mac.then you have flowtype installed with visual result with every key stroke:
Upvotes: 5
Reputation: 2474
Try this one:
Adding Flow to React Native
https://medium.com/react-native-training/getting-started-with-react-native-and-flow-d40f55746809
Hope this helps!
Upvotes: 1