Skip to main content

Types

FTL supports the following types: Int (64-bit), Float (64-bit), String, Bytes (a byte array), Bool, Time, Any (a dynamic type), Unit (similar to "void"), arrays, maps, data structures, and constant enumerations. Each FTL type is mapped to a corresponding language-specific type. For example in Go Float is represented as float64, Time is represented by time.Time, and so on.

User-defined types referenced by a verb will be automatically exported as FTL types.

Basic types

The following table shows how FTL types map to language-specific types:

FTLGo
Intint
Floatfloat64
Stringstring
Bytes[]byte
Boolbool
Timetime.Time
AnyExternal
UnitN/A
Map<K,V>map[K]V
Array<T>[]T

Data structures

FTL supports user-defined data structures, declared using the idiomatic syntax of the target language.

type Person struct {
Name string
Age int
}

Generics

FTL has first-class support for generics, declared using the idiomatic syntax of the target language.

type Pair[T, U] struct {
First T
Second U
}

Type enums (sum types)

Sum types are supported by FTL's type system.

Sum types aren't directly supported by Go, however they can be approximated with the use of sealed interfaces:

//ftl:enum
type Animal interface { animal() }

type Cat struct {}
func (Cat) animal() {}

type Dog struct {}
func (Dog) animal() {}

Value enums

A value enum is an enumerated set of string or integer values.

//ftl:enum
type Colour string

const (
Red Colour = "red"
Green Colour = "green"
Blue Colour = "blue"
)

Type aliases

A type alias is an alternate name for an existing type. It can be declared like so:

//ftl:typealias
type UserID string

Type aliases are useful for making code more readable and type-safe by giving meaningful names to types that represent specific concepts in your domain.