Fl4m3Ph03n1x

Fl4m3Ph03n1x

Dialyzer Unknown type for struct

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?

Marked As Solved

NobbZ

NobbZ

Somewhere in your code you are refering to Event.t but you have not an alias MyApp.Event there.

Also Liked

tme_317

tme_317

Also if you want to cut down on the boilerplate for the exact same result you can use typed_struct. I don’t usually like to add tons of “helper” deps like this but in this case it’s so natural I use it all the time.

Fl4m3Ph03n1x

Fl4m3Ph03n1x

@NobbZ If only Dialyzer told me which file has the issue, it would be a start :stuck_out_tongue: I found it now, thanks!

@tme_317 I am a fan of the library and I use it in my projects.
However, I decided to not bring that yet to work. People may feel overloaded.

Besides, I find it better to use vanilla examples in the forum, this way the number of people able to help me is bigger :smiley:

Last Post!

Fl4m3Ph03n1x

Fl4m3Ph03n1x

@NobbZ If only Dialyzer told me which file has the issue, it would be a start :stuck_out_tongue: I found it now, thanks!

@tme_317 I am a fan of the library and I use it in my projects.
However, I decided to not bring that yet to work. People may feel overloaded.

Besides, I find it better to use vanilla examples in the forum, this way the number of people able to help me is bigger :smiley:

Where Next?

Popular in Questions Top

electic
Hi, I am new to Elixir. I am trying to use the DateTime component to insert a date into MySQL however the there seems to be no way to fo...
New
New
ovidiubadita
Hey all, I discovered Elixir and I love it. I always wanted to learn a functional programming and I intended to go for Haskell, but afte...
New
jononomo
For some reason my phoenix channels are working for me in my local dev environment, but as soon as I deploy via Docker, I get a 403 error...
New
dokuzbir
I want to highlight html closing tags when i click a html tag. That works in .html files but doesnt work for html.eex templates. How can...
New
fireproofsocks
Forgive me if this is obvious, but how does one delete a database record WITHOUT selecting it first? Ecto.Repo — Ecto v3.14.0 has exampl...
New
shijith.k
I am trying to start a new phoenix project with elixir 1.9, but mix phx.new does not work. It says that ** (Mix) The task "phx.new" could...
New

Other popular topics Top

dokuzbir
I want to highlight html closing tags when i click a html tag. That works in .html files but doesnt work for html.eex templates. How can...
New
nsuchy
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
New
joeerl
Hello again - after a longish gap I’ve decided I really must dig into Elixir and see what’s been happening here - so I have a few questio...
New
dogweather
I wrote this comment on r/haskell, and it’s not popular there. :wink: But I think I’m on to something… Haskell reminds me of Java, and e...
New
shijith.k
I am trying to start a new phoenix project with elixir 1.9, but mix phx.new does not work. It says that ** (Mix) The task "phx.new" could...
New
sergio
Kind of like when jquery came out, it was super necessary. Existing drag and drop libraries have a bunch of baggage to support old browse...
New

We're in Beta

About us Mission Statement