TypeCheck - Fast and flexible runtime type-checking for your Elixir projects

I’m thinking typespecs with runtime checks (“typespecs with teeth”) provide the opportunity to cleanup a bit of duplication in my function signatures. Suppose a function had the following signature:

@spec do_a_thing(User.t(), Project.t()) :: binary()
def do_a_thing(%User{} = user, %Project{} = project) do

I tend to pattern match on struct arguments for enforcement and explicitness. However, now that these typespecs can provide the same, is there value in continuing to include them?

I will continue to pattern match when necessary for multiple function heads with the same name, but beyond that seems a bit redundant. The following seems cleaner and easier to maintain:

@spec do_a_thing(User.t(), Project.t()) :: binary()
def do_a_thing(user, project) do
9 Likes