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

Creating Optional Fields out of strict record

$
0
0

The type system in ReScript requires you to think about things up front since you can’t modify the types later.

If you have a type with an optional field of name and a type where name is required, they aren’t really the same type.

You can use type spreading to share common keys across types.

type person = {
  name: string,
  age: int,
}
  

type user = {
  ...person,
  address?: string // we might not have an address for all users
}

type billing = {
  ...person,
  address: string // we have to have an address for shipping
}

Viewing all articles
Browse latest Browse all 2592

Trending Articles