Skip to content

@as support for @obj makes inconsistent conversion #6440

Closed as not planned
Closed as not planned
@mununki

Description

@mununki

Thanks to the PR #6412, we can rename the returned js object key name. But I found little inconsistent with the exisiting @as usage on record.

type t0 = {@as("a") type_: string}

@obj
external make: (@as("b") ~type_: string=?) => t0 = ""

let t0 = { type_: "t0"}

let t1 = make(~type_="t1")

let make = make

generated to

var t0 = {
  a: "t0"
};

var t1 = {
  b: "t1" // shouldn't be a?
};

function make(prim) {
  var tmp = {};
  if (prim !== undefined) {
    tmp.b = prim; // shouldn't be tmp.a = prim?
  }
  return tmp;
}

IMO, @as("b") would make rename the argument to b, but not affecting the returned value that needs to be kept a by @as("a")

What do you think? @DZakh

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