这是一个新手问题,但我无法在任何地方找到快速答案。
Facebook 的 Reason 语言是否支持可空类型?如果有,是什么形式?
正如 Neil 所提到的, Reason 本身具有option
类型。但是,如果您必须处理来自 JavaScript 的可能值null
或undefined
值,还有Js.Nullable.t
. 它可以option
在需要时使用Js.toOption
.
还有一些更具体的类型只能分别处理一个null
或undefined
另一个,Js.Null.t
但Js.Undefined.t
你很少需要这些。为了完整起见,我提到它们。
没有null
。我们最接近的是选项变体。请参阅下面的各种文档:
https://reasonml.github.io/docs/en/newcomer-examples.html#using-the-option-type https://reasonml.github.io/docs/en/variant.html#option
null
让我知道您是否会在 JavaScript 中遇到某种特定的情况,您希望看到 Reason 等价物。