Cast closed object to open one?



I’m trying to use reason-react together with reason-apollo. I’ve got a nested object, a response to a GraphQL query. I want to take a piece of it and pass it to the other component as a prop:

/* Parent component does this: */

<Message message=message/>

/* Message component: */

let make = (~message, _children) => {

  render: _self => {

However, the types don’t match:

  60 ┆ ->allMessages
  61 ┆ -> => {
  62 ┆   <Message message=message/>
  63 ┆ })
  64 ┆ ->Belt.List.toArray

  This has type:
    option({. "direction": option(string)})
  But somewhere wanted:
    {.. "direction": option(string)}

So it complains that the object I got from ReasonApollo is a closed object, whereas my component expects to get an open object.

How do I deal with this?



Apologies for the post above :man_facepalming:

I spent quite a bit of time trying to solve this error, only because apparently I can’t read plain words the compiler printed… I’ts not about one object being open and the other closed! It’s about one being an option(...) and the other not.

Sorry again, I’ll try not to triple-check my code before posting next time.


No worries! This is a great sign of an error message we can make better, and we wouldn’t have seen it without your post (and kind followup)!