# Behaviour and Typespec

**URL:** <https://forum.elixirforum.com/t/behaviour-and-typespec/3408>\
**Category:** Questions\
**Tags:** behaviours\
**Created:** [January 25, 2017, 2:12pm UTC](https://forum.elixirforum.com/t/behaviour-and-typespec/3408 "2017-01-25T14:12:30Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![madeinussr](https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/madeinussr/32/3837_2.png) [@madeinussr](https://forum.elixirforum.com/u/madeinussr)\
**Post date:** [January 25, 2017, 2:12pm UTC](https://forum.elixirforum.com/t/behaviour-and-typespec/3408/1 "2017-01-25T14:12:30Z")

</div>

Hi, all,

Mb it’s silly question 😔, but: is there any possibility to define a behaviour in a function’s spec?

for example we have:

```elixir
defmodule SomeBehaviour do
  @callback do_it() :: any()
end

defmodule Adopter1 do
  @behaviour SomeBehaviour

  def do_it(), do: :done
end

defmodule Adopter2 do
  @behaviour SomeBehaviour

  def do_it(), do: :not_done
end

defmodule SomeModule do
  # So, what's the right @spec for this function, if I'd like to specify SomeBehaviour adopters usage?
  # The first thought is to use just SomeBehaviour.t with @type t :: __MODULE__ in SomeBehaviour definition,
  # but as for me it seems too strict and any adopter will not pass the check
  def do_it_with(adopter), do: adopter.do_it()
end

```

Thanks.

---

<div class="post-metadata">

**Author:** ![michalmuskala](https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/michalmuskala/32/20288_2.png) [@michalmuskala](https://forum.elixirforum.com/u/michalmuskala)\
**Post date:** [January 25, 2017, 3:18pm UTC](https://forum.elixirforum.com/t/behaviour-and-typespec/3408/2 "2017-01-25T15:18:44Z")

</div>

Probably the best you can do is to spec it as `module` - the type system is not powerful enough to express something more advanced.

The idea to add `@type t :: module` in the behaviour is probably a good one. While it’s still the same when checked with dialyzer, it expresses much more when treating type specs as documentation.

---

<div class="post-metadata">

**Author:** ![madeinussr](https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/madeinussr/32/3837_2.png) [@madeinussr](https://forum.elixirforum.com/u/madeinussr)\
**Post date:** [January 25, 2017, 3:34pm UTC](https://forum.elixirforum.com/t/behaviour-and-typespec/3408/3 "2017-01-25T15:34:20Z")

</div>

Unfortunately `@type t :: module` + `@spec(SomeBehaviour.t)` will check just for any module, not a behaviour adopter. ☹ well, let it be
