Unknown type warnings from Dialyzer when using custom type in Ecto?

I’m trying to set up my Phoenix project with Dialyzer. The inbuilt Elixir Language Server in VS Code has been working fine, but I now want to run some checks in CI, and slowly add some types to a few key places in the application.

When I run mix dialyzer, I’m getting a series of “unknown type” warnings on my Ecto Schema structs.

:0:unknown_type
Unknown type: App.Comments.Comment.t/0.

It looks to me like Ecto has failed to generate the .t() type. Could this be because I’m using Ecto.ULID, a custom type, for my primary keys? My cursory attempt to add typespecs to that library, following the example in Ecto.UUID, didn’t seem to work so I’m not quite sure where to look next.

Any suggestions?

It looks to me like Ecto has failed to generate the .t() type.

Ecto does not automatically define t() type (neither does defstruct), you need to define it yourself.

3 Likes

Oh! I’m not quite sure what led me to think it did. Thanks!