Typespec for traverse_errors/2 - why the function shall return a string?

I’m using Ecto.Changeset.traverse_errors/2 to get a nested map of errors and translate it into JSON API response. However it was pointed out in the review that according to the typespec the function passed to traverse_errors should return a string.

@spec traverse_errors(t, (error -> String.t) | (Changeset.t, atom, error -> String.t)) :: %{atom => [String.t | map]}

My question is - what is the rationale behind that? Is there a problem with returning something else? I’m actually returning a tuple, passing basically an identity function to it.

3 Likes