Writing Type Specifications

Learn how to use typespecs and dialyxir to identify possible bugs in the code.

What are typespecs?

While Elixir isn’t a statically typed language, it does give the ability to specify types using typespecifications, or typespecs. Typespecs are specifications that communicate the intended use of a function.

For example, a function add/2 that adds two numbers a and b might have the following specification:

Get hands-on with 1200+ tech skills courses.