How do you typecheck the shape of an Immutable.JS data structure generated from fromJS
using Flow? Plain old JS blobs can be typed very accurately using an object literal notation:
type ObjectShape = {
a: number,
b: string,
c: {
d: number,
},
e: Array<number>
};
const obj: ObjectShape = { // hyper-accurate
a: 1,
b: '2',
c: {
d: 3,
},
e: [4]
}
However, on the Immutable.js side, there seem to be two major complications:
It appears that Immutable.js's
fromJS
method returnsany
(https://github.com/facebook/immutable-js/blob/master/type-definitions/immutable.js.flow#L764), so the following is not caught as an error in Flow:const map: boolean = fromJS(obj) // this is totally not true, but Flow can't tell
It appears that map shapes cannot be described using an object-like notation per How to describe Immutable.js Map shape with Flow (or is this information outdated?).
I'm genuinely confused on how to get Flow to understand Immutable.js, maps in particular. From what I can tell, Flow loses a lot of intelligence about the codebase when the data is living within Immutable.js structures instead of plain JS primitives.