Reasonml记录与JS对象

时间:2018-07-07 16:11:28

标签: ocaml record reason bucklescript

说我定义以下类型:

type queueParams = {
  durable: bool
};

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

然后调用以下内容:

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

结果:

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

如何传递正确的事物?为什么我要传递的东西没有记录?点标记的含义是什么?

1 个答案:

答案 0 :(得分:5)

ReasonML对这两种解释不同:

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

基本上,用双引号引起来的键是特殊的Javascript对象类型Js.t('a)的简写形式,该类型目前不推荐使用。

您可以play around with an example here。请注意,两种类型在转换为Javascript时如何区别对待。

在此处详细了解不赞成使用的语法:

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

相关问题