Representing IO in a spec

  @spec greeting(String.t) :: String.t
  def greeting(name \\ nil, io \\ IO) do
    # ...
  end

Per this article, I am inserting the IO module as an input to my function for testing purposes.

How do I represent this in my spec?

In io.ex in the Elixir source code. It appears that they use a type called device:

@type device :: atom | pid
1 Like

Appreciate your promptness!

Adding that isn’t throwing errors (it wasn’t before either, though).

Still not sure this is right, as I am passing a module made up of functions… Dialyzer would be the way to validate this?

The type of a module name is atom().

1 Like