# Dialyzer Unknown type for struct

**URL:** <https://forum.elixirforum.com/t/dialyzer-unknown-type-for-struct/28336>\
**Category:** Questions\
**Tags:** dialyzer, defstruct, types\
**Created:** [January 17, 2020, 2:02pm UTC](https://forum.elixirforum.com/t/dialyzer-unknown-type-for-struct/28336 "2020-01-17T14:02:16Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Fl4m3Ph03n1x](https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/fl4m3ph03n1x/32/11709_2.png) [@Fl4m3Ph03n1x](https://forum.elixirforum.com/u/Fl4m3Ph03n1x)\
**Post date:** [January 17, 2020, 2:02pm UTC](https://forum.elixirforum.com/t/dialyzer-unknown-type-for-struct/28336/1 "2020-01-17T14:02:17Z")

</div>

## 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:

```elixir
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?

---

<div class="post-metadata">

**Author:** ![NobbZ](https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/nobbz/32/27235_2.png) [@NobbZ](https://forum.elixirforum.com/u/NobbZ)\
**Post date:** [January 17, 2020, 2:07pm UTC](https://forum.elixirforum.com/t/dialyzer-unknown-type-for-struct/28336/2 "2020-01-17T14:07:14Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![tme\_317](https://forum.elixirforum.com/letter_avatar_proxy/v4/letter/t/0ea827/32.png) [@tme\_317](https://forum.elixirforum.com/u/tme_317)\
**Post date:** [January 17, 2020, 2:29pm UTC](https://forum.elixirforum.com/t/dialyzer-unknown-type-for-struct/28336/3 "2020-01-17T14:29:22Z")

</div>

Also if you want to cut down on the boilerplate for the exact same result you can use [typed\_struct](https://github.com/ejpcmac/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.

---

<div class="post-metadata">

**Author:** ![Fl4m3Ph03n1x](https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/fl4m3ph03n1x/32/11709_2.png) [@Fl4m3Ph03n1x](https://forum.elixirforum.com/u/Fl4m3Ph03n1x)\
**Post date:** [January 17, 2020, 2:59pm UTC](https://forum.elixirforum.com/t/dialyzer-unknown-type-for-struct/28336/4 "2020-01-17T14:59:59Z")

</div>

@NobbZ If only Dialyzer told me which file has the issue, it would be a start 😛 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 😃
