Skip to content

Feature suggestion: syntax for Js.Dict.t literals #6301

Closed
@johnridesabike

Description

@johnridesabike

I've been working with code that uses "hash map" style JS objects, and the ReScript syntax for declaring them can be tedious. (Or rather, the lack of syntax to declare them is tedious.)

Consider this JS:

const data = {
  a: foo,
  b: bar,
  c: baz,
};

Compared with this ReScript:

let data = Js.Dict.fromArray([
  ("a", foo),
  ("b", bar),
  ("c", baz),
])

That's a lot of extra parentheses and brackets to express the same thing. When you inline it somewhere (such as inside a function argument), then it's even more noisy and less readable.

My suggestion is to include a dedicated syntax similar to Js.t objects. Maybe something like this:

@dict
let data = {
  "a": foo,
  "b": bar,
  "c": baz,
}

Would this make sense to add?

Metadata

Metadata

Assignees

No one assigned

    Labels

    staleOld issues that went stale

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions