This is accomplished using behaviours:
defmodule A do
@callback simple_function(integer()) :: non_neg_integer()
end
defmodule B do
@behaviour A
@impl A
def simple_function(int), do: ...
end
I’ll add, however, that it’s not advisable to create behaviours if your goal is really only to re-use some typespecs. Two different functions sharing a common, duplicated typespec is not a code smell.


















