Background
I have a custom struct and I want to define a type for it so I can run Dialyzer checks. However Dialyzer is complaining that I have an unknown type.
Code
I have a struct that defines an Event and I have defined the following type:
defmodule MyApp.Event do
@enforce_keys [:event_id, :type, :version]
defstruct event_id: nil,
type: "event",
version: nil
@type t() :: %__MODULE__{
event_id: non_neg_integer,
type: String.t(),
version: non_neg_integer
}
@spec new(map) :: __MODULE__.t()
def new(map),
do: %__MODULE__{
event_id: Map.get(map, "event_id"),
type: Map.get(map, "type"),
version: Map.get(map, "v")
}
end
Problem
However when I run mix dialyzer
I get the following error:
:0: Unknown type âElixir.Eventâ:t/0
What am I missing?