最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Static type checking with immutable.js and Facebook flow - Stack Overflow

programmeradmin4浏览0评论

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

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

Share Improve this question edited May 22, 2015 at 1:28 SaidbakR 13.5k23 gold badges111 silver badges202 bronze badges asked Dec 10, 2014 at 3:17 Kilamanjaro KablamKilamanjaro Kablam 2913 silver badges4 bronze badges 5
  • Maybe you can use accessors to statically annotate that dynamic part of the Immutable.js. – user217782 Commented Dec 10, 2014 at 12:47
  • Do you mean wrap an immutable object with a custom object that provides annotated accessors? – Kilamanjaro Kablam Commented Dec 10, 2014 at 17:34
  • @brandon-tilley I hesitated to use the flowtype tag because there is a pletely unrelated project that has to do with typography called FlowType.JS. – Kilamanjaro Kablam Commented Dec 11, 2014 at 4:10
  • Any luck on this @KilamanjaroKablam ? – Riley Lark Commented May 29, 2015 at 1:10
  • 1 Flow more about JS types. You can use npmjs./package/react-immutable-proptypes for check prop types. It works for me. – Dmitry Manannikov Commented Jun 7, 2015 at 20:30
Add a ment  | 

2 Answers 2

Reset to default 6

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

https://github./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)

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

发布评论

评论列表(0)

  1. 暂无评论