Skip to main content
Version: Next

Type Annotations

Annotations

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:

type parameter =
["Back"]
| ["Claim"]
| ["Withdraw"];
type storage = {
owner : address,
goal : tez,
deadline : timestamp,
backers : map<address, tez>,
funded : bool
};
@entry
const back = (param : unit, store : storage) : [list<operation>, storage] => { // Annotation
if (Tezos.get_now() > store.deadline) {
return failwith ("Deadline passed.");
}
else {
return match(Map.find_opt (Tezos.get_sender(), store.backers)) {
when(None()): do {
let backers = Map.update(Tezos.get_sender(), Some(Tezos.get_amount()), store.backers);
return [[], {...store, backers:backers}];
};
when(Some(x)): [[], store]
}
};
};