Flow support for Expo?

Hi,

I am wondering will Expo support flow by default or provide flow config at initialization of the repo? It is kinda of pain of setting up flow in app under expo, giving me thousands of flow errors and warnings. Things getting better after I copied .flowconfig from react-native init, but there’s still a dozen of errors. Is there any solution for flow support?

Thanks!

Have you tried starting out with the create react native app flowconfig and going from there? https://github.com/react-community/create-react-native-app/tree/master/create-react-native-app

2 Likes

Thanks for the quick response. Yes I did, but it failed because create-react-native-app cli doesn’t seems to support npm 5. It doesn’t have flow-bin installed on node_module by glancing at their github repo so I wonder if they support flow by default. Actually if create-react-native-app is the way to go, why not have the project repo created by Expo XDE to keep sync?

npm 5 is broken and not working with create-react-native-app or create-react-app and breaks in all sort of weird situations. please do not use it, use yarn instead

the reasons for why expo and crna are separate are outlined in docs https://docs.expo.io/versions/latest/guides/create-react-native-app.html

1 Like

This is how I got Flow to work in my Expo project.

  1. I use Atom and Nuclide
  2. In Atom → preferences → packages → search for nuclide and click on it|
  3. scroll down to nuclide-flow and tick box says “Use the Flow binary included in each project’s flow bin”
  4. ensure your expo project has a .flowconfig (this is the one I used) https://github.com/react-community/create-react-native-app/blob/master/react-native-scripts/template/.flowconfig
  5. but I added the following

./node_modules/.

at the end of the [ignore] block, line 32 at time of writing.

3 Likes

I don’t think there are flow types for Expo yet.

How i’m getting around it is, in my .flowconfig under [options] I added:

module.name_mapper='^expo$' -> '<PROJECT_ROOT>/flowTypes/expoTypes'

Then I created the folder ‘flowTypes’ and a file inside of ‘expoTypes’.


// @flow

const WebBrowser: any = {};

export default {};
export { WebBrowser };

Then I add every expo type in here that I eventually use so that it fixes my flow errors. Added bonus, is that it’s very easy to see what APIs i depend on expo now. All i need to do is look at this file ha.

expo-sdk has some flow types built-in, eg: https://github.com/expo/expo-sdk/blob/master/src/Calendar.js. personally i’m not bullish on flow. i removed .flowconfig from projects by default and i (personally, i do not speak for expo as a whole) don’t recommend using flow. its community adoption is stagnant compared to typescript and it introduces breaking changes too frequently.

2 Likes

@notbrent , are you personally more hopeful for typescript? Do you think its worth it today to go typescript + expo? I haven’t tried yet

@notbrent I’m surprised that this is your stance on flow. Doesn’t flow make Expo adoption easier? I was under the impression that Flow might win over TypeScript in the long run because of its support for React and that it seems to integrate a bit more easily with React, especially in React Native project.

Could I be missing something? Flow is quite painful at the moment (smaller community, poor documentation, freaking breaking changes) but I was under the impression that the wind is blowing in Flow’s direction.

1 Like

typescript definitely has the wind at its back, flow has it blowing right into its face

1 Like

I’m not trying to spark a debate, these are genuine questions as I’m trying to be future proof as much as possible.

Why is Expo based on flow? Does Expo provide TypeScript support?
Current Flow has some really overwhelming issues as you mentioned below. Do you think these won’t be resolved 6 or 12 months down the line?

Thank you so much for contributing to this discussion.

  • expo-sdk uses flow because it seemed like a good option at the time when we started writing it
  • expo-sdk does not provide type definitions for typescript, but i believe some folks maintain them on their own on definitelytyped
  • i don’t know about the future, but the current trajectory of flow in terms of community adoption is not promising. flow is a tool that works great for facebook but otherwise i think is not widely used. for example, if you look at npm-stat.com, typescript has about 10x as many installations. you can also compare the definitelytyped repo to flow-typed on npm and see how many more definitions are available / how frequently they are updated. additionally, vscode has excellent typescript integration and is quickly becoming the most popular editor.
  • alternatives like reasonml may eat flows lunch when it comes to react integration
2 Likes