Flow: Object.assign vs spreading

Reading Time: < 1 minute

Recently I ran into an interesting example of how the flow is interpreting 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 two 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

If you have found a spelling error, please, notify us by selecting that text and pressing Ctrl+Enter.

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

Leave a Comment

Your email address will not be published. Required fields are marked *

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: