Immutable-js: Read only types for Record

Created on 11 Apr 2018  路  3Comments  路  Source: immutable-js/immutable-js


For v4.0.0-rc.9, Record({ counter: 0 }) corresponds to type RecordOf<{ counter: number }>,

It would be great if it corresponded to type RecordOf<$ReadOnly<{counter: number }>>.

Would a PR making this change to the Flow types be welcome?

Here's an example of a change to immutable.js.flow:

// The type of runtime Record instances.
- type RecordOf<Values: Object> = RecordInstance<Values> & Values;
+ type RecordOf<Values: Object> = RecordInstance<Values> & $ReadOnly<Values>;

Most helpful comment

Great idea - in fact everywhere Values is referenced (sometimes as T) this should be the correct behavior.

All 3 comments

Great idea - in fact everywhere Values is referenced (sometimes as T) this should be the correct behavior.

Should we also use $Exact<> ?

The semantics are as follows:

T: { a: number, b: string }

foo: $Exact<T> = { a: 3 } // error
bar: $Exact<T> = { a: 3, b: 'hello' } // fine

I'm not sure that's necessary since Exact and & do not always interact together the way you might expect, but if you find that it improves type correctness I'm open to looking at PRs

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ntgn81 picture ntgn81  路  3Comments

jamesgpearce picture jamesgpearce  路  4Comments

Delapouite picture Delapouite  路  3Comments

jshthornton picture jshthornton  路  3Comments

papercuptech picture papercuptech  路  4Comments