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

How to create a record value from a subtype record value?

$
0
0

Yes, you cannot safely spread here.

That only works when bar’s own fields are all optional.

type foo = {x: int, y: int}
type bar = {...foo, z?: int}

let foo = {x: 1, y: 2}
let bar: bar = {...foo, z: 3}

Also, you can spread a supertype like bar into its subtype:

type foo = {x: int, y: int}
type bar = {...foo, z: int}

let bar = {x: 1, y: 2, z: 1}
let foo = {...bar, y: 3}

but this erases all fields that are not in foo.


Viewing all articles
Browse latest Browse all 1784

Trending Articles