Skip to content

Syntax

Shapes

A shape describes the structure of an array or an object field by field. It is written in braces after a type name, fields are separated by commas, a trailing comma is allowed.

An array with two fields.

array{id: int, name: string}
type
fields
field
key
type
field
key
type

resultTypeLang\Type\NamedTypeNode

An object with one field.

object{id: int}
type
fields
field
key
type

resultTypeLang\Type\NamedTypeNode

A field is either a type alone or a key: Type pair. The kinds of keys are described in Shape keys.

A question mark (?) before the colon marks a field that may be absent: key?: Type. It is not the same as a nullable type of the value.

The field may be absent.

array{key?: Type}
type
fields
field?
key
type

resultTypeLang\Type\NamedTypeNode

The field is present, its value may be null.

array{key: ?Type}
type
fields
field
key
nullable
type

resultTypeLang\Type\NamedTypeNode

A shape is sealed: it describes all the fields there are. An ellipsis (...) as the last element unseals it, the value may then carry fields beyond the described ones.

key and any other fields.

array{key: Type, ...}
type
fields · unsealed
field
key
type

resultTypeLang\Type\NamedTypeNode

Template arguments after the ellipsis describe the types of the other fields: of the values, or of the keys and the values. The syntax is that of generics.

user, and any other fields with string keys and object values.

array{user: User, ...<string, object>}
type
fields · unsealed
field
key
type
args
type
type

resultTypeLang\Type\NamedTypeNode

The ellipsis is always the last element. A shape may consist of the ellipsis alone, and may be empty.

array{...<string, object>}
type
fields · unsealed
args
type
type

resultTypeLang\Type\NamedTypeNode

array{}
type
fields

resultTypeLang\Type\NamedTypeNode