Dialyxir
Learn more about typespecs by practicing Dialyxir to take it to the next level.
We'll cover the following
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 give Dialyxir a try. In the same hexify project from the previous lesson, add Dialyxir to your dependencies in mix.exs:
Get hands-on with 1400+ tech skills courses.