Flow: Object.assign vs spreading

Recently I ran into an interesting example of how the flow is making interpretation of the values without the provided defined type.

Open Flow Try playground

So if to use Object.assign flow assumes that shapes of all other arguments in the assign are the same as the first argument.

There are 2 ways how to overcome this type of limitation.

  1. Use spreading instead

Open Flow Try playground

  1. Assign all values to initial empty object

Open Flow Try playground

Olena Sovyn
Senior Software Engineer (London, UK). I ❤ React, Redux, lodash, React Storybook, and functional programming overall. Always open for learning something new

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Spelling error report

The following text will be sent to our editors: