type person = {
id: int,
name: string,
img: string
}
At runtime, the person type has many more properties attached to it. Is there a clever way to strip any properties that are not defined in ReScript? I could manually map it, but I wonder if there’s an alternative approach.
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')