reasonml 记录与 JS 对象
reasonml record vs JS object
假设我定义了以下类型:
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
我怎样才能传递正确类型的东西?为什么我传递的不是记录?那个点符号是什么意思?
ReasonML 对这两个的解释不同:
let jsObject = {"durable": true};
let reasonRecord = {durable: true};
基本上,用双引号包裹键是特殊 Javascript 对象类型 Js.t('a)
的简写符号 - 目前已弃用。
你可以play around with an example here。请注意,当转换为 Javascript.
时,两种类型的处理方式有所不同
在此处详细了解已弃用的语法:
假设我定义了以下类型:
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
我怎样才能传递正确类型的东西?为什么我传递的不是记录?那个点符号是什么意思?
ReasonML 对这两个的解释不同:
let jsObject = {"durable": true};
let reasonRecord = {durable: true};
基本上,用双引号包裹键是特殊 Javascript 对象类型 Js.t('a)
的简写符号 - 目前已弃用。
你可以play around with an example here。请注意,当转换为 Javascript.
时,两种类型的处理方式有所不同在此处详细了解已弃用的语法: