Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
在 Rescript 中,可以Record以这种格式定义 a:
Record
type record1 = { a : String }
但不是:
type record2 = { [a] : String }
我正在寻找可以编译为 JS的记录,例如:
{ [Op.or]: [12,13] }
上面的用例来自Sequelize,参考在这里。
Sequelize
我目前的解决方案:
%raw(`{[Op.or]:[12,13]}`)
目前尚不完全清楚您打算如何与Op构造交互,是否可以绑定到它,但这里有一个示例,并且Js.Dict.t有效地产生相同的输出:
Op
Js.Dict.t
module Op = { @val external or: string = "Op.or" } Js.Dict.fromList(list{ (Op.or, [12, 23]) })
但是,它不会直接编译为您想要的 JS,如果您依赖于实际解析源代码的东西,这可能是一个问题。但除此之外,我相信这应该满足您的要求。