Quantcast
Channel: ReScript Forum - Latest posts
Viewing all articles
Browse latest Browse all 2592

Remove unused properties from external type

$
0
0

I had some code where updating an (external) object via spread syntax, all “untyped” properties has been removed from the updated copy, since the generated code copied the properties one by one (no spreading).
Maybe you can use this “hack”.

Don’t have the code right now, but could reconstruct it later.

EDIT:
Here we go:

Code:

type person = {
  id: int,
  name: string,
  img: string
}

let p: person = %raw(`{
  id: 1,
  name: "john doe",
  img: "",
  age: 99,
}`)

let p' = {
  ...p,
  id: p.id,
}

Console.log(p)
Console.log(p')

Output:

{
  id: 1,
  name: "john doe",
  img: "",
  age: 99,
}
{
  id: 1,
  name: "john doe",
  img: "",
}

Viewing all articles
Browse latest Browse all 2592

Trending Articles