Flow doesn't recognize platform-specific react-native files
In recent react-native releases, common practice for files that need platform-specific implementations is to turn foo.js into two files: foo.android.js and foo.ios.js. Flow obviously doesn't know what to make of this, which leads to "Required module not found" errors.
As a temporary workaround you can add module.name_mapper for each such file, but maintaining this list is a lot of work, and the end result is that half your code isn't type-checked at all.
Ideally, flow would recognize this pattern, and be able to type-check both implementations against the import (and against each other) to ensure they implement the same interface.
+1
Yup, this is super valuable. We should have a solution for this.
Not sure what the proper way to "upvote" this would be. But: +1
Would be great to see this being worked on. Ideally this should be configurable to support different platforms like .windows.js or .web.js.
Just recently started converting a React Native project into flow and encountered this.
+1
I just ran into this as well.
Another workaround is to add the following to .flowconfig:
module.file_ext=.ios.js
module.file_ext=.js
module.file_ext=.jsx
module.file_ext=.json
Of course you'll have to edit this if you want to check .android or .web
I think this issue can be closed as module.file_ext can totally handle this without any modification in flow. And it makes things explicit.
Maybe just more docs (maybe another example in the doc)?
I still see an issue here: how can flow validate all files? I mean flow might want to choose .ios.js first, but this might leads to issue if someone update another ext (ex: .web.js, defined after) and do not respect the API of .ios.js version.
@MoOx Flow will need to run through all three code paths.
I don't think this works now, but it could work like this
flow check --file_ex=.ios.js,.js
flow check --file_ex=.android.js,.js
flow check --file_ex=.web.js,.js
Maybe you could do it now with 3 different .flowconfig
Thanks for the alternative suggestion @DaleJefferson, could you please elaborate on how this works for you? I just get flow: unknown option '--file_ex' when trying this on the CLI.
@bkrem I think there is just a typo, try --file-ext.
@bkrem
I don't think this works now, but it could work like this
It does not work for me, I was just suggesting that it could work like that.
Ah right just a misunderstanding, I thought you meant the suggestion above yours was deprecated rather than your own being a suggestion :)
The problem using the config is that flow will stop on the first file it will find. So if you .ios.js is the first, flow won't check other implementations. That's why trying to do that for each extensions might be a good idea.
module.file_ext=.ios.js works
but module.file_ext=.android.js doesn't. Anyone else experiencing this?
@mhollweck the problem is that flow will stop for the first file it will find. It won't resolve and try multiple files. So you might need to use flow with multiples config or try using a CLI options to run flow 2 times... (or maybe use ios by default and run 1 additional time with .android.js)...
@MoOx I know that flow only checks the first file it will find but even if I ONLY check android files it won't recognise my android.js files! Am I the only person with this issue?
@mhollweck : React Native's default .flowconfig is set up to ignore all .android.js files. You can work around this by changing -.*/*[.]android.js to .*/node_modules/.*/*[.]android.js in the .flowconfig of your project.
Any progress on this? I currently have this issue with react-native 0.35 and flow-bin 0.32