Granted

问题描述 投票:0回答:1

在JavaScript中,有三个值。

  • Result.granted
  • Result.denied
  • Result.neverAskAgain

如何将它们转换为变体?

type result =
    | Granted
    | Denied
    | NeverAskAgain;
ocaml reason bucklescript
1个回答
0
投票

你可以绑定到这些值,然后写一个函数,将这些值转换成一个变量。绑定到这些值。

然后把它们转换为变量。

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
  };
© www.soinside.com 2019 - 2024. All rights reserved.