Skip to content

Support ad-hoc object types to map to JS objects #157

@Lupus

Description

@Lupus

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions