Search⌘ K

Dialyxir

Discover how Dialyxir enhances Elixir development by automating type consistency checks using Dialyzer. Learn to add Dialyxir to your project, interpret warnings, and ensure your typespecs align with your functions. This lesson helps you understand how to maintain reliable code and reduce runtime errors through effective type analysis.

What is Dialyxir?

Since Elixir is a dynamically typed language, the compiler doesn’t bother to evaluate whether our typespecs are correct. The compiler only cares if the number of function arguments, or arity, and function name match.

Typespecs don’t seem useful. We can remove them without upsetting the compiler. Worse, typespecs could easily fall out of alignment with the functions they support and lead to confusion. We need some kind of tool to automate type checking just as Credo automates style checks.

Jeremy Huffman has written a library called Dialyxir, which is a set of easy-to-use mix tasks for Dialyzer, an Erlang tool named from the characters in DIscrepancy AnaLYZer for ERlang. The tool actually analyzes our code for type consistency using our typespecs for extra information. Let’s ...