Extends types like in TS (&)

Hello. Can I extends types like in TS?

type Foo = { foo: string }
type Bar = Foo & { bar: string }
type Baz = Bar & { baz: string }

// Baz === { foo: string; bar: string; baz: string }

ReScript allows ‚Äútype spreading‚ÄĚ for object types (but not for record types):

type foo = {"foo": string}

type bar = {...foo, "bar": string}

type baz = {...bar, "baz": string}

let b: baz = {
  "foo": "test",
  "bar": "test",
  "baz": "test",
}

Playground Link

4 Likes

I thought of this initially.
But spread can not be used on an object to create a new object

eg: let c = {...b, "foo":"new"} this gives a compile error.

Thank you, all!
:tada::tada::tada::tada::tada::tada::tada::tada::tada: