【发布时间】:2018-09-12 23:57:44
【问题描述】:
我正在尝试为 https://github.com/oblador/react-native-keychain/blob/master/typings/react-native-keychain.d.ts#L76 编写绑定
getGenericPassword 如果出错则返回false,否则返回object (credentials)。我不确定这种联合类型是否可以合理地表示,但更好的 API 将是一个选项(选项(凭据))的结果。但是,如何在绑定文件中转换 Promise<boolean | credentials> -> Js.Promise.t(option(credentials))。下面是一个模板。
感谢您的帮助。
[@bs.deriving abstract]
type credentials = {
service: string,
username: string,
password: string,
};
/* TODO convert the actual return value
Js.Promise.t(option(credentials)) to more reason type
Js.Promise.t(option(credentials)) */
[@bs.module "react-native-keychain"] [@bs.scope "default"]
external getGenericPassword: unit => Js.Promise.t(option(credentials)) = "";
【问题讨论】:
标签: ocaml ffi reason bucklescript union-types