Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/svg/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
ReasonML javascript记录字段_Javascript_Types_Ocaml_Reason_Bucklescript - Fatal编程技术网

ReasonML javascript记录字段

ReasonML javascript记录字段,javascript,types,ocaml,reason,bucklescript,Javascript,Types,Ocaml,Reason,Bucklescript,假设我有以下Bucklescript类型: type amqp; [@bs.val] external amqpLib: amqp = "Amqp"; [@bs.module] external amqplib : amqp = ""; class type amqpConnectionT = [@bs] { pub createChannel: unit => unit; pub close: unit => unit }; type amqpC

假设我有以下Bucklescript类型:

type amqp;

[@bs.val] external amqpLib: amqp = "Amqp";

[@bs.module] external amqplib : amqp = "";

class type amqpConnectionT =
  [@bs]
  {
    pub createChannel: unit => unit;
    pub close: unit => unit
  };

type amqpConnection = Js.t(amqpConnectionT);

let make = () => amqplib;

[@bs.send] external connect : (amqp, string) => Js.Promise.t(amqpConnection) = "";

let connectAmqp = (input: string, amqpClient: amqp) : Js.Promise.t(amqpConnection) => connect(amqpClient, input);

let makeConnection = (input) => make() |> connectAmqp(input, _);
然后是以下代码:

let start = () =>
  Amqp.makeConnection("amqp://localhost")
  |> Js.Promise.then_(connection => {
    Js.log(connection);
    connection.createChannel();
    Js.Promise.resolve(connection);
  });

start();
这在以下情况下失败:

The record field createChannel can't be found.
为什么??我的类型注释怎么不正确

在ReasonML中公开这样的成员方法的正确方法是什么?

如果它来自JS,请尝试
connection##createChannel()


当您使用访问器时,编译器认为连接是一个记录,那么##语法是什么呢?为什么不是唱片?这些都记录在哪里?这些都记录在bucklescript中,上面的代码以一种不推荐的方式绑定amqp。有关新的绑定模式,请参见。这将使绑定的使用更加简单。