LIGO is strongly and statically typed. This means that the compiler checks how your contract processes data, ensuring that each function's expectations are met. If it passes the test, your contract will not fail at run-time due to some inconsistent assumptions on your data. This is called type checking.
LIGO types are built on top of Michelson's type system.
For quick reference, you can find all the built-in types here.
Type aliasing consists of renaming a given type when the context calls for a more precise name. This increases readability and maintainability of your smart contracts. For example we can choose to alias a string type as an animal breed - this will allow us to communicate our intent with added clarity.
The above type definitions are aliases, which means that
stringare interchangeable in all contexts.
Often contracts require complex data structures, which in turn require well-typed storage or functions to work with. LIGO offers a simple way to compose simple types into structured types.
The first of those structured types is the record, which aggregates types as fields and indexes them with a field name. In the example below you can see the definition of data types for a ledger that keeps the balance and number of previous transactions for a given account.
Complementary to records are the variant types, which are described in the section on pattern matching. Records are a product of types, while variant types are sums of types.
In certain cases, the type of an expression cannot be properly inferred by the compiler. In order to help the type checker, you can annotate an expression with its desired type. Here is an example: