gen_js_api
gen_js_api copied to clipboard
Support ad-hoc object types to map to JS objects
Typescript definitions often define ad-hoc object types for parameters or return values, like this for example:
class TimeUuid extends Uuid {
/* ... */
getDatePrecision(): { date: Date, ticks: number };
}
Would be awesome to be able to just write in .mli:
(* class 'TimeUuid' *)
module Time_uuid : sig
class t :
Ojs.t
-> object
inherit Uuid.t
(* method 'getDatePrecision' *)
(* signature: (): { date: Date; ticks: number; } *)
method get_date_precision : unit -> < date : Date.t; ticks : int > [@@js.call "getDatePrecision"]
end
val js_of_t : t -> Ojs.t [@@js.cast]
val t_of_js : Ojs.t -> t [@@js.cast]
end
One could define a record type for this in advance, but this type would be somewhat artificial given that it's anonymous in "upstream" typescript typings and is not ever reused anywhere.