问题标签 [rescript]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
0 回答
96 浏览

reactjs - 在脚本和夏令时获取范围内的日期

我的网站上有一个日历,它获取开始日期和结束日期,并将它们传递给计算 . 让我们有开始日期Mon Mar 29 2021 03:00:00 GMT+0300 (Eastern European Summer Time),结束日期是Mon Apr 05 2021 03:00:00 GMT+0300 (Eastern European Summer Time) ;这个函数应该返回 ["30/3/2021","31/3/2021","1/4/2020","2/4/2020","3/4/2020","4/4/ 2020"]

这是 toUTCDateString 函数,它接受一个日期并给出它的字符串版本

这些功能在夏令时更改之前工作正常;我们获得了一个小时,所以一天因为某种原因停留在那里 任何机构之前都面临过这个问题,谁来处理这样的时间问题?

0 投票
1 回答
159 浏览

unused-variables - 在 Rescript 中抑制警告:Js.Promise.make

在 Rescript 中做出承诺时:

ReScript 编译器将在unused variable reject.

有没有办法抑制这个错误?

0 投票
1 回答
69 浏览

types - 如何使用变体选项在脚本中键入函数参数?

我想做以下事情。但似乎我无法使用变体选项之一键入函数参数。在脚本中实现这一目标的正确方法是什么? 

这里是游乐场

0 投票
4 回答
220 浏览

f# - Ocaml 中是否有单例变体的用例?

我一直在阅读 F# 文章,他们使用单例变体来创建不同的不兼容类型。但是在 Ocaml 中,我可以使用私有模块类型或抽象类型来创建不同的类型。在 Ocaml 中使用 F# 或 Haskell 等单例变体是否很常见?

0 投票
1 回答
98 浏览

reason - 如何在 ReScript 中为任意记录类型实现哈希函数?

我是第一次探索 ReScript。我想使用记录类型作为我的键类型来构建一个哈希图,并且我正在寻找有关实现哈希函数的指导。

这是我的 ReScript 代码:

我浏览了文档并在线搜索,但没有找到有关如何实现该hash功能的任何指导。

在期望您实现的其他编程语言(例如 Java )中hashCode(),有无处不在的工具来支持组合现有的散列函数。

我查看了Belt.HashMapString 的实现,看看是否有任何提示,看起来 HashMapString 使用caml_hash_mix_string

访问和组合“哈希混合”函数的最惯用方式是什么?这些是否可以通过 ReScript 的漂亮界面获得?

0 投票
3 回答
279 浏览

javascript - 如何在 ReScript 中执行 document.createElement

ReScript 似乎是编写 JS 代码的更好方法,但我无法找到应该是简单的单行文档的内容。

我如何调用函数document.createElement()

我通过查看此页面尝试了 Js.document、Dom.document:https ://rescript-lang.org/docs/manual/latest/api ,但该代码在操场上出现错误:

documentJs中找不到值Dom中找不到
document

0 投票
2 回答
167 浏览

ocaml - 如何为多态对象类型定义抽象(不透明)接口?

原因机器学习

奥卡姆

如何定义模块类型 A t('a) 使其抽象但与实现中的开放多态对象类型兼容?

0 投票
2 回答
61 浏览

reason - How can I type a JS module method from Reason?

In an effort to refactor an existing JS based WebUI into a ReasonML, I'm trying to embed a some refactored code. Currently I'm doing this by embeddeding all the ReasonML code (so far) inside an iframe.

Space is extremely limited, so rather than adding a reasonml module that does the same, I would like to use one of the JS methods in my ReasonML code, but I'm not clear in on the syntax to type the call. In JS, the call is simply:

There doesn't appear to be an explicit constructor for the toastr object, but I tried to do this regardless:

and later in the code:

The above doesn't compile, failing on the bread->success("") line with the message:

How do make this work (in bs 8.4.2)?


EDIT #2

I've gotten even closer to the JS output I'm hoping will work with:

which I can invoke:

which produces the JS:

but it's throwing an exception at run time because it can't find the toastr module.

I think I'm on to a different problem now?

0 投票
1 回答
103 浏览

reason - Rescript Record: Key as Array

在 Rescript 中,可以Record以这种格式定义 a:

不是

我正在寻找可以编译为 JS的记录,例如:

上面的用例来自Sequelize,参考在这里

目前的解决方案

0 投票
3 回答
240 浏览

javascript - 如何在 ReScript 中使用 JavaScript Material Design 库?

我正在尝试在 Rescript/React 应用程序中使用该material-ui库。下面的代码将显示一个按钮:

显示的按钮是基本的,我无法更改基本属性variant="contained", 例如color="primary"无法识别它们。我尝试将string第一行中的类型更改为 TypeScript@material-ui/core/Button文件中的类型,但没有成功。我尝试使用%%raw()and %raw(),但它们非常有限。我无法使用它们返回的对象,因为 ReScript 不知道它们的类型。此外,我无法在函数内部调用React.useEffect()using %raw()(因为它不返回任何内容) 。make

在 TypeScript 中,我可以使用对象和调用函数,而不需要关于它们的类型信息。

有没有办法在 ReScript 中做同样的事情,还是我必须自己添加所有的输入信息(如果我想使用库)?