Right now it's possible to declare multiple clauses for `@spec` as we can 
see in Typespecs documentation 
<https://github.com/elixir-lang/elixir/blame/9fd2633b6e25d9676db0d6c3e9cf7e951caebfa3/lib/elixir/pages/Typespecs.md#L180-L183>,
 
but we don't have the same feature for `@type` and `@typep`.

Since `@spec` allows for it, one -- me, actually -- would think the same 
could be done to `@type(p)`. Here's a silly example for when this would be 
helpful:

```
@type error_details(t) :: {:invalid, :invalid_atom, term} when t: atom
@type error_details(t) :: {:invalid, :invalid_boolean, term} when t: binary
@type error_details(t) :: {:invalid, :invalid_whatever, term} when t: 
user_custom_type

@spec foo(atom) :: {:ok, binary} | {:error, error(atom)
@spec foo(binary) :: {:ok, binary} | {:error, error(binary)
@spec foo(user_custom_type) :: {:ok, binary} | {:error, 
error(user_custom_type)
def foo(value)
```

IMO, having this feature for `@type` (prob for `@typep` as well, just for 
consistency) is complementary to multiple `@spec` clauses, allowing for 
reuse of typespecs.

-

Related 
to https://groups.google.com/g/elixir-lang-core/c/2xJ4VKMws40/m/qkeRrHugDgAJ

Related 
to 
https://github.com/elixir-lang/elixir/blame/9fd2633b6e25d9676db0d6c3e9cf7e951caebfa3/lib/elixir/pages/Typespecs.md#L180-L183

-- 
You received this message because you are subscribed to the Google Groups 
"elixir-lang-core" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to elixir-lang-core+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/elixir-lang-core/24393ca9-b21b-4ef6-a0cc-c4d333be0d98n%40googlegroups.com.

Reply via email to