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}
resultTypeLang\Type\NamedTypeNode
An object with one field.
object{id: int}
resultTypeLang\Type\NamedTypeNode
A field is either a type alone or a key: Type pair. The kinds of keys are
described in Shape keys.
Optional fields
Section titled “Optional fields”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}
resultTypeLang\Type\NamedTypeNode
The field is present, its value may be null.
array{key: ?Type}
resultTypeLang\Type\NamedTypeNode
Unsealed shapes
Section titled “Unsealed shapes”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, ...}
resultTypeLang\Type\NamedTypeNode
Typed shapes
Section titled “Typed shapes”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>}
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>}
resultTypeLang\Type\NamedTypeNode
array{}
resultTypeLang\Type\NamedTypeNode
The ellipsis must be the last.
array{...<string, object>, user: User}
errorMalformedSyntaxException Invalid shape, a field, "," or "}" is expected
A shape and template arguments cannot be written together on a named type: the arguments of a shape stand after its ellipsis.
array<int>{user: User}
errorUnexpectedTokenException Unexpected "{"