ddoronin
Hey folks! I want to add documentation for individual fields on a struct/typedstruct, and I’m wondering about available options? I’m new in elixir.
typedstruct do
@typedoc "Foo struct is so foo"
# the foo field is so foo
field :foo, String.t()
# the bar field is so bar
field :bar, String.t()
end
Trending in Questions
I having some trouble figuring out if I have set myself too strict of standards for my production server. Currently I can handle 75% of r...
New
Hello,
I’m trying to build a basic Phoenix web-app, and I’d like to use Tailwind.
However, when I launch mix phx.server, I get an error...
New
Hi everyone.
My team and I have been working on a fairly modest app based around video streaming and chat, but we’ve landed a customer t...
New
I really like the adapter patterns that ecto, nebulex, waffle, etc. use and would love find something similar for a key management servic...
New
Hello folks!
So at work, we are seeing some situations where we have to define some “fixed” strings that are used across the codebase in...
New
I’m working on a small exercise involving update_in/3, and I came up with this solution:
data = %{
name: "Periodic Table",
category:...
New
How Can I Optimise Compile Time Dependencies
I have been building an elixir application for about 2 years now. Many modules and files ha...
New
Other Trending Topics
Edit: 2026 May 15 - This post is archived.
Mob is alive!!
Main docs: mob v0.7.11 — Documentation
A bit of explanation for the slightly c...
New
A little off-topic, but I feel like people here have a good head on their shoulders.
I used to be quite good at making software. Was luc...
New
Hey. Is there anyone here who creates agents in their apps? Not talking about using agents, but creating them. I’m finding it pretty diff...
New
I fully migrated to my own harness from Anthropic/Gemini and I think it’s time to share it. Welcome DSH, the DeepSeek Harness, fully writ...
New
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New
There has been a thread to discuss the Stack Overflow Developer Survey on this forum every year since 2018, so here’s yet another one for...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #ai
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #blog-post
- #elixirconf-us
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #elixirconf-eu
- #api
- #forms
- #security
- #metaprogramming











Showing Posts 1 to 10- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
thelastinuit
You can create custom typespec and document with this
msimonborg
The convention is to create a type called
tusing the@typeattribute.You can reference your new type from other modules with
MyApp.Foo.t()just as you wouldString.t().Typespecs
Defstruct#types
ddoronin
typedstruct will generate the t() under the hood. My question was more about individual fields on a struct. Those are :foo and :bar in my example:
What you are suggesting is something like this:
Obviously I don’t want to create a type for every single field just to document it, because I have dozens of fields and hundreds of structs.
msimonborg
Sorry I guess I misunderstood your question! I’m not familiar with that library, I thought it was pseudocode
IMO,
t()is self-documenting as far as what types you expect in the fields. If I wanted more documentation I would add it to the top-level@typedoc. e.g.Maybe there’s a feature in the
typedstructlibrary, but that’s what I would do in vanilla Elixirsbuttgereit
Assuming that you’re creating documentation with ExDoc vs. trying to create simple code comments that describe the field I’ll document the individual fields directly in the struct’s
@typedoc. So your:becomes something like:
To my knowledge, there’s no great way to document the fields individually that will render in something like ExDoc or iex
hlike you might expect/want.sbuttgereit
I should note that this assumes this is for public functions/modules. When the code being documented is private, I’ll just use normal code comments to include any helpful documentation with the understanding that won’t render in ExDoc’s output.
msimonborg
btw, this was not what I was suggesting, my original suggestion is outlined in my second comment, but this is a reasonable approach if you want thorough documentation for your fields which may be themselves complex types. It is probably overkill if your fields are built-in types
ddoronin
yep, this is for public modules, and I’m using ExDoc.
ddoronin
@msimonborg Gotcha! It was probably mixed up in my head with another answer given by thelastinuit. It seems like @typedoc with the “Fields” section is the most common way to document struct fields.
msimonborg
No worries
It’s also the same documentation approach for function options and the like