Nil and typespec primitives - is it redundant to write integer() | nil?

Is it redundant to write integer() | nil? Which primitives allow for nil?

nil is an atom:

iex(1)> is_atom(nil)
true

so any typespec that allows atoms through will also permit nil - atom() for instance.

3 Likes

I thought nil was treated specially. So essentially, integer, String.t, and anything besides atom does not include nil?

Correct.

No, nil doees not get any special typespec treatment.

2 Likes