string = "dirname" [@bs.module "axios"] external simpleGet: string => Js.Promise.t">

ReasonML JS 模块的进入和 JS Object 的类型声明

代码:

[@bs.module "path"] external dirname : string => string = "dirname"
[@bs.module "axios"] external simpleGet: string => Js.Promise.t('a) = "get"
[@bs.module "axios"] external get: string => Js.t({. params: {. "id": int}}) => Js.Promise.t('a) = "get"

let opts = [%obj {params: {id: 123}}];

get("https://www.baidu.com", opts)
 |> Js.Promise.then_(value => {
     Js.log(value)
     Js.Promise.resolve(value)
 })
 |> Js.Promise.catch(err => {
     Js.log(err)
     Js.Promise.resolve(-1);
 })