29

I've been using Immutable.js for my react app and I'm loving it. Facebook also released Flow. Flow would let me do very cool things like compile time validation of prop types. The problem is that my props are generally Immutable objects. Is there a good way to use Immutable.js and Flow together?

Given an Immutable.js object parameter can I use Flow to somehow specify the type of the object it should be wrapping? Within that object I might have strings, numbers, booleans, and more importantly other Immutable.js objects.

SaidbakR
  • 11,955
  • 16
  • 89
  • 173

2 Answers2

6

At the time of writing, you can use the two together by grabbing the interface file from here:

https://github.com/facebook/immutable-js/blob/master/type-definitions/immutable.js.flow

  1. Create a directory within your project, for example interfaces.
  2. Create a .flowconfig if it doesn't exist, and add the following lines

.flowconfig

[libs]
interfaces/

This will look in the ./interfaces/ directory for Flow definitions.

Although linking to a resource is frowned upon on SO, it that case it makes sense as that will be the most up to date (I'm assuming FB will keep it update as they update the core library)

Chris
  • 43,908
  • 26
  • 122
  • 165
  • 3
    Would it be possible to get an example of it in use. What would the type for an immutable version of this look like? `type someObject = {fieldOne: string, fieldTwo: number};` – m14t Aug 19 '16 at 00:21
  • 1
    Not sure why the downvote? It is almost identical @Geoffrey Abdallah's answer, yet was answered prior to his? – Chris Aug 19 '16 at 10:24
  • Thanks for this great help. – JamesG Oct 18 '17 at 04:08
3

Edited to add that flowtypes have been added since most recent major version.

Original answer:

Looks like integration between Flow and Immutable.js is in development but not yet complete.

Geoffrey Abdallah
  • 3,009
  • 12
  • 25