Skip to content

renaming fields in inline records doesn't work when destructuring #6438

Closed
@tsnobip

Description

@tsnobip

thanks to #6391, it's now possible to rename fields of inline records:

type t = Foo({ @as("renamed") name: string, age: int}) | Bar
let foo = Foo({ name: "foo", age: 10 })

generates:

var foo = { TAG: "FOO", renamed: "foo", age: 10 }

But if you try to get the value then it bugs:

let getName = t =>
  switch t {
  | Bar => "bar"
  | Foo({name}) => name
  }

generates:

function getName(t) {
  if (typeof t !== "object") {
    return "bar";
  } else {
    return t.name; // the error is here, it should be t.renamed
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions