# `ExUtils.Typespecs`
[🔗](https://github.com/sheharyarn/ex_utils/blob/main/lib/ex_utils/typespecs.ex#L1)

Elixir utility methods for typespecs.

# `literal`

```elixir
@type literal() :: atom() | integer()
```

Supported literals for dynamic typespec generation

# `from_list`

```elixir
@spec from_list([literal()]) :: Macro.t()
```

Builds a union type from a list of static values.

This is useful for generating typespecs for enums when the values are already
known at compile-time. To use it, you must call this inside a `@type`
definition inside an `unquote(...)` expression.

Raises an error for invalid literals.

## Examples

```elixir
# Given a list of static values:
@statuses [:open, :closed]
@priorities [1, 2, 3]

# You can use them in a @type definition:
@type status :: unquote(Typespecs.from_list(@statuses))
@type priority :: unquote(Typespecs.from_list(@priorities)) | nil
```

The above is equivalent to writing these typespecs by hand:

```elixir
@type status :: :open | :closed
@type priority :: 1 | 2 | 3 | nil
```

---

*Consult [api-reference.md](api-reference.md) for complete listing*
