I'm defining a State type with an exact shape:
type State = {| someString: string, someNumber: number |};
My initial state satisfies this definition:
const initialState : State = {
someString: 'hey',
someNumber: 1,
};
Creating function that takes state and returns a modified copy of it does not, however:
function doStuff (state : State) : State {
return {
...state,
someNumber: 2,
};
}
src/flowTest.js:10 10: return {
^ object literal. Inexact type is incompatible with exact type
9: function doStuff (state : State) : State {
^^^^^ exact type: object type
Is this flow not understand destructuring or am I missing something? I did notice that changing the type definition to be non-strict (removing | around the brackets) will let this code pass. However I'm trying to make I prevent any typos.
Thanks!
Flow's current support for object spread is a bit lacking still, and Exact object syntax is also relatively new. In this case https://github.com/facebook/flow/issues/2405 appears to be the issue you are hitting.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With