flow icon indicating copy to clipboard operation
flow copied to clipboard

Flow doesn't recognize platform-specific react-native files

Open eapache opened this issue 11 years ago • 39 comments

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.

eapache avatar Oct 14 '15 14:10 eapache

+1

rops avatar Mar 07 '16 12:03 rops

Yup, this is super valuable. We should have a solution for this.

samwgoldman avatar Mar 07 '16 21:03 samwgoldman

Not sure what the proper way to "upvote" this would be. But: +1

reallistic avatar Apr 14 '16 03:04 reallistic

Would be great to see this being worked on. Ideally this should be configurable to support different platforms like .windows.js or .web.js.

ntharim avatar Apr 22 '16 20:04 ntharim

Just recently started converting a React Native project into flow and encountered this.

+1

j-wang avatar May 26 '16 18:05 j-wang

I just ran into this as well.

bgeihsgt avatar Jun 09 '16 00:06 bgeihsgt

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

chetstone avatar Jun 12 '16 23:06 chetstone

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)?

MoOx avatar Jun 24 '16 12:06 MoOx

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 avatar Jun 24 '16 13:06 MoOx

@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

DaleLJefferson avatar Jun 24 '16 13:06 DaleLJefferson

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 avatar Jul 02 '16 15:07 bkrem

@bkrem I think there is just a typo, try --file-ext.

MoOx avatar Jul 03 '16 04:07 MoOx

@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.

DaleLJefferson avatar Jul 04 '16 11:07 DaleLJefferson

Ah right just a misunderstanding, I thought you meant the suggestion above yours was deprecated rather than your own being a suggestion :)

bkrem avatar Jul 04 '16 11:07 bkrem

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.

MoOx avatar Jul 04 '16 11:07 MoOx

module.file_ext=.ios.js works but module.file_ext=.android.js doesn't. Anyone else experiencing this?

mhollweck avatar Jul 14 '16 09:07 mhollweck

@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 avatar Jul 18 '16 04:07 MoOx

@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 avatar Jul 19 '16 11:07 mhollweck

@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.

fagerbua avatar Oct 13 '16 12:10 fagerbua

Any progress on this? I currently have this issue with react-native 0.35 and flow-bin 0.32

jarretmoses avatar Nov 26 '16 15:11 jarretmoses