Pular para o conteúdo

Type grammar

Este conteúdo não está disponível em sua língua ainda.

Types may be named directly or qualified through a namespace:

String
Geometry.Point

Generic arguments use angle brackets in type syntax:

Array<String>
Table<String, Int>

Generic call arguments use doubled angle brackets so they remain distinct from comparison operators:

Array.create<<Int>>(4, 0)

Append ? when a value may also be nil:

String?

The general union spelling joins alternatives with |:

String | Int | nil

This type union is distinct from a declared tagged union: a tagged union gives alternatives named cases and optional payloads.

Array types have equivalent short and named forms:

{String}
Array<String>

Typed tables likewise have two forms:

{[String]: Int}
Table<String, Int>

A tuple lists positional element types:

(String, Int, Boolean)

A function type lists named parameters and an optional result:

function(value: Int): String
function(message: String)

Parentheses group compound types when necessary. Type spelling does not cause implicit conversions: aliases aside, values must satisfy the exact expected type or an explicitly permitted union/interface relationship.