Cast closed object to open one?

reasonreact
interop

#1

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) => {
  ...component,

  render: _self => {
    <section>
      {str(message##direction->getWithDefault("-"))}
    </section>
  }
};

However, the types don’t match:

  60 ┆ ->allMessages
  61 ┆ ->Belt.List.map(message => {
  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?

Cheers!


#2

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.
Cheers!


#3

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)!