2

Say I define the following types:

type queueParams = {
  durable: bool
};

class type amqpChannelT = [@bs] {
  pub assertQueue: string => queueParams => Js.Promise.t(unit);
};

Then calling the following:

channel##assertQueue("exampleQueue", {"durable": bool});

Results in:

This has type:
    {. "durable": bool}
  But somewhere wanted:
    queueParams (defined as

How can I pass the right type of thing? Why is the thing I'm passing not a record? And what is the meaning of that dot notation?

Abraham P
  • 15,029
  • 13
  • 58
  • 126

1 Answers1

5

ReasonML interprets these two differently:

let jsObject = {"durable": true};
let reasonRecord = {durable: true};

Basically, wrapping keys with double-quotes is a short-hand notation for the special Javascript object type Js.t('a) - which is currently deprecated.

You can play around with an example here. Note how the two types are treated differently when converted to Javascript.

Read more about the deprecated syntax here:

https://bucklescript.github.io/docs/en/object-deprecated

Hari Gopal
  • 718
  • 3
  • 7
  • Thanks for the explanation! Very clear. Just one small followup, what does that dot notation syntax mean? the {. ...? – Abraham P Jul 08 '18 at 12:22
  • @AbrahamP The type definition `{. "key": type}` is for any and all `Js.t('a)` (JS special objects). It's what I first noticed as being _off_ in your example. It's very similar to the (closed) object type definition `{. key: type}`, described here: https://reasonml.github.io/docs/en/object , but note how the former has its keys wrapped with double-quotes. I'm not certain, but I think this is a special type exposed by Bucklescript, guaranteed to compile to a identically shaped JS object. – Hari Gopal Jul 08 '18 at 14:10