tl;dr: How to change the following binding to be able to write Intl.DateTimeFormat.make()
instead of Intl_.DateTimeFormat.make()
?
type dateTimeFormat;
[@bs.deriving abstract]
type formatOptions = {
[@bs.optional]
weekday: string,
[@bs.optional]
day: string,
[@bs.optional]
month: string,
};
module Intl_ {
module DateTimeFormat {
module Impl {
type t;
};
[@bs.new] external make: unit => Impl.t = "Intl.DateTimeFormat";
[@bs.send] external format: (Impl.t, Js.Date.t) => string = "";
};
}
Intl_.DateTimeFormat.make()
->Intl_.DateTimeFormat.format(Js.Date.make())
->Js.log;
The issue
Without the underscore, this would compile to:
var Impl = /* module */[];
var DateTimeFormat = /* module */[/* Impl */Impl];
var Intl = /* module */[/* DateTimeFormat */DateTimeFormat];
console.log(new Intl.DateTimeFormat().format(new Date()));
exports.Intl = Intl;
The issue is that var Intl = ...
shadows the global Intl
, and thus breaks new Intl.DateTimeFormat()
.