# Types

The following covers the definition of type and their composition and type expressions.

### Definition

There are three different kinds of type definitions in TreeLDR:

#### Empty Type

The empty type is defined by simply declaring the name of the type directly followed by a semicolon.

#### Normal Type

A normal type also declares properties that can be applied to the instances of this type. Properties are listed inside the definition between braces:

The type of each property is specified after a colon `:`

using a *type expression*. If a property listed in the definition is declared outside the type definition, it is not required to specify the type of the property again.

#### Type Alias

Lastly, it is possible to define type aliases. Such a type is defined using a *type expression*.

### Type Expression

A type expression is a composition of existing types by union, intersection and restriction.

#### Union

The union between two or more types is expressed using the `|`

operator.

An instance of this type is also an instance of at least one of the listed sub-types.

#### Intersection

The intersection between two or more types is expressed using the `&`

operator.

An instance of this type is also an instance of all the listed sub-types.

#### Range Restriction

Range restrictions are used to select a subset of a type by restricting the range of one of its properties. There are two kinds of range restrictions: universal and existential.

A universal range restriction is built using the `all`

keyword:

This denotes the type of all values such that all objects of `someProperty`

are instances of `RestrictedType`

.

Similarly, the existential range restriction is built using the `any`

keyword:

This denotes the type of all values such that at least one object of `someProperty`

is an instance of `RestrictedType`

.

Range restrictions are usually part of an intersection:

Last updated