Defining Flow types for and creating Immutable Records

438 Views Asked by At

I’m trying to get Flow working with Immutable.js Records.

I’m defining my record as:

const MyRecord = new Immutable.Record({id: undefined})

and then creating records with

new MyRecord({id: 1})

When I run Flow, I get an error on the new MyRecord constructor call that says:

constructor call Constructor cannot be called on Record

Am I defining the record incorrectly? Or do I need to some how specify the type for the constructor?

I am using flow-bin 0.33.0 and immutable 3.8.0 inside a React Native 0.38.0 project.

Thanks!

1

There are 1 best solutions below

2
On BEST ANSWER

You're trying to call a constructor on an object that is already constructed. Record is creating a new class not constructing an object. Remove the new keyword from the first statement and it should work.