Generic Type

View Source

Note

This rule was named consistent_generic_type before 4.2.0.

term() or any() should be used consistently in typespecs.

Avoid

This is a convention aimed at ensuring consistency, rather than a coding issue.

Depending on your choice, you should avoid:

% the default "avoid".
-type mytype() :: any().

or:

-type mytype() :: term().

Prefer

Depending on your choice, you should prefer:

% the default "prefer".
-type mytype() :: term().

or:

-type mytype() :: any().

Rationale

Defining a specific "term" type enhances consistency across your codebase.

Options

  • preferred_type :: term | any

    • default: term

Example configuration

{elvis_style, generic_type, #{preferred_type => term}}