Flow: Sealing Objects when using spread or Object.assign

Created on 16 May 2016  ·  10Comments  ·  Source: facebook/flow

It would be great to be able to keep an object sealed somehow when using spread or Object.assign.

The use case I'm thinking of is for redux inside a reducer.
Currently if I misspell the key name in an update, flow can't check it as it just thinks it's an extra property to an object.

feature request

Most helpful comment

Any news on the matter?

All 10 comments

The new exact object types should help here.

@ianobermiller It seems that sealed objects/exact object types are still not compatible with the spreading operator.

```javascript
/* @flow */
type State = {|
username: ?string,
password: ?string
|}

const state: State = {
username: null,
password: null
}

const validState:State = state
const invalidState:State = { ...state } // flow-error: Inexact type is incompatible with exact type object type
```
Do you know if there are any plan on supporting this feature?
It's a really common use pattern in redux reducers.

Thank you in advance 👍

@kristian-puccio did you find any alternative way to handle this issue?

No unfortunately still waiting on a solution.

On 23 December 2016 at 02:30, Matteo Mazzarolo notifications@github.com
wrote:

@ianobermiller https://github.com/ianobermiller It seems that sealed
objects/exact object types are still not compatible with the spreading
operator.

/* @flow */
type State = {|
username: ?string,
password: ?string|}
const state: State = {
username: null,
password: null
}
const validState:State = stateconst invalidState:State = { ...state } // object literal. Inexact type is incompatible with exact type object type

Do you know if there are any plan on supporting this feature?
It's a really common use pattern in redux reducers.

Thank you in advance 👍

@kristian-puccio https://github.com/kristian-puccio did you find any
alternative way to handle this issue?


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/facebook/flow/issues/1793#issuecomment-268823287, or mute
the thread
https://github.com/notifications/unsubscribe-auth/ACA_f5TCdEdTxJ0lPvp4E1X1ZbLBq0l3ks5rKpewgaJpZM4IfFZe
.

This would be extremely useful.

Any news on the matter?

Agree with @c10b10 - this would help us a lot!

This looks like something that will take a while.

Hoping we get some progress on this soon! Currently struggling to type my reducers, which make heavy use of the object spread operator.

@mmazzarolo, that doesn't seem to be an error on Flow v0.80.0 anymore.

@kristian-puccio fixed.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

STRML picture STRML  ·  48Comments

opensrcery picture opensrcery  ·  88Comments

blax picture blax  ·  83Comments

cletusw picture cletusw  ·  52Comments

NgoKnows picture NgoKnows  ·  40Comments