Syntax Lookup

Enter some language construct you want to know more about.

{ key: type }

A record type is a named set of typed fields.

A record type defines a fixed structure with named fields.

Example

ReScriptJS Output
type myRecord = {
  name: string,
  age: int,
}

let myRecord: myRecord = {name: "Ada", age: 36}

let label = switch myRecord {
| {name, age} => name ++ " (" ++ Int.toString(age) ++ ")"
}

Nested Record Types

Since ReScript 12, record types can be declared inline inside another record type:

RES
type profile = { name: string, settings: { notifications: bool, theme: string, }, }

Nested record types are useful when the inner shape belongs only to its parent. If it needs to be referenced independently, give it a separate named type.

References