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:

Where Next?

Popular in Questions Top

itssasanka
Hi all, Trying to get some more clarity over utc_datetime and naive_datetime for Ecto: https://hexdocs.pm/ecto/Ecto.Schema.html#module-...
New
pgiesin
This should be a simple problem but I just can’t seem to figure it out. I have a standalone Elixir app that won’t find the database. Dep...
New
SoCreat
i’m a new one to elixir which editor can i use vs code? or atom? Thanks! :smiley:
New
mgjohns61585
Could someone help me? I'm making my first elixir program, number guessing game. I can't figure out how to convert the user's guess from ...
New
qwerescape
Is there a way to get the call stack or stack trace at any point in the code? Not from exceptions, but an expression that returns how the...
New
fayddelight
I tried installing elixir 1.11.2 erlang 23.3.4 via asdf in my zsh shell. Enabled the versions locally and globally. When I list them ...
New
shahryarjb
Hello, I have map which I want to convert it to string like this: the map: %{last_name: "tavakkoli", name: "shahryar"} the string I ne...
New
vonH
When I run the Plug and I recompile I wind up having to use Ctrl C to quit iex and start again. Witht the help of rlwrap I can use the cu...
New
wernerlaude
In AR this is so simple @articles = current_user.articles How to do in Ecto? def index(conn, _params) do current_user = conn.assig...
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

Other popular topics Top

shahryarjb
Hello, I get Persian date from my client and convert it to normal calendar like this: def jalali_string_to_miladi_english_number(persi...
New
JakeBecker
TL;DR: I’ve just released an implementation of Microsoft’s IDE-independent Language Server Protocol for Elixir. It adds language support ...
1140 51847 244
New
sergio_101
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
New
New
Harrisonl
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service. Currently when I de...
New
chrismccord
This release brings a number of exciting features, including integration with the new Phoenix LiveDashboard and Phoenix LiveView. There h...
New
vertexbuffer
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
New
freewebwithme
Using vs code and installed ElixirLS: support and debugger. And I got an error popped up on start up says Failed to run ‘elixir’ comma...
New
ashish173
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
New
WestKeys
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
New

We're in Beta

About us Mission Statement