在JavaScript中,有三个值。
Result.granted
Result.denied
Result.neverAskAgain
如何将它们转换为变体?
type result =
| Granted
| Denied
| NeverAskAgain;
你可以绑定到这些值,然后写一个函数,将这些值转换成一个变量。绑定到这些值。
然后把它们转换为变量。
type t';
[@bs.module "result"] external granted: t';
[@bs.module "result"] external denied: t';
[@bs.module "result"] external neverAskAgain: t';
type t = Granted | Denied | NeverAskAgain;
let fromJS = t' =>
switch (t' === granted, t' === denied, t' === neverAskAgain) {
| (true, _, _) => Granted
| (_, true, _) => Denied
| (_, _, true) => NeverAskAgain
};