Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to write a Flow Type definition for ImmutableJS Types?

I see that ImmutableJS has flow type annotations now but how do I define the type? For example:

const state : ??? = Immutable.fromJS({ name: 'chet', tags: ['something']})

I can define the type from normal JS but how do I say that this is an Immutable.Map with certain keys?

like image 574
Chet Avatar asked Aug 25 '16 22:08

Chet


1 Answers

The problem right now is that immutable flow types only support one type definition for each key and value combination.

So immutable.Maps accepts Map<keyType, valueType>

and immutable.List accepts List<valueType>

Immutable.fromJS({ name: 'chet', tags: ['something']})

is equivalent to Map({name: 'chet', tags: List(['something])}

so, your type definition would be

Map<(string) | ('name', 'tags'), string | List<string>>

like image 144
l2silver Avatar answered Sep 22 '22 13:09

l2silver