Skip to content

Support mel.as in %mel.obj #1002

@jchavarri

Description

@jchavarri

Currently, it's possible to define JS object literals in Reason syntax, e.g.

let headers = {"Content-Type": "application/json"};

But translating this snippet to OCaml syntax triggers an error:

let headers = [%mel.obj { Content-Type = "application/json" }]
                                 ^
Error Syntax error

One can use mel.rawto workaround, e.g.

let headers = [%mel.raw {| {"Content-Type": "application/json"} |}]

with the downside that inferred types are lost, and it's not possible to annotate the value with the corresponding < Content-Type : string > Js.t type.

Having a way to redefine generated JS fields when using %mel.obj using mel.as would be very useful.

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