This SysSeder guide examines Elixir’s gradual type checking. Version 1.20 was released on June 3, 2026; this is a dated archive explanation, not a claim that the release happened today.
Growing codebases benefit from several kinds of feedback: tests, compiler diagnostics and separate analysis tools such as Dialyzer. Their results are not interchangeable. Whether a diagnostic is easy to read is contextual; this article does not report a survey or personal deployment experience.
We will explain sets, inference and diagnostics, then examine two small synthetic modules. These examples are documentation-informed and statically inspected, not compiled here. They are learning material, not a claim that a project has been upgraded or verified.
Understanding gradual typing in Elixir
The useful starting point is Elixir’s own design rather than a blanket comparison with TypeScript. Set-theoretic types describe collections of possible values and combine them through set operations.
Elixir values are immutable, while a variable name can be rebound to another value. Rebinding does not mutate the earlier value. A gradual design must account for existing dynamic programs; that does not prove that stricter typing would necessarily break Phoenix or LiveView.
Instead, Elixir's gradual type system is designed around three core principles:
- Gradual: dynamic typing information can retain a range of possibilities. Current inference does not require users to opt in with new function annotations. A lack of warnings is not permission to omit input validation.
- Soundness: this is a property of the typing design, not a promise that a warning-free application cannot fail. Dynamic uncertainty and runtime checks remain relevant; logic errors, authorization mistakes and operational failures are outside such a blanket guarantee.
- Developer-friendly inference: existing patterns and expressions supply useful information. Reduced annotation work is valuable, but it does not eliminate tests, documentation or careful handling of uncertain inputs.
What are Set-Theoretic Types?
At the heart of Elixir's type system is the concept of sets. In this mental model, a type is simply a set of values. For example:
- The type
integer()is the set of all integers. - The type
atom()is the set of all atoms. - A union such as
integer() or binary()includes either set. The originalsring()is a typo, and the new system’s set notation usesor; do not confuse it with legacy typespec syntax.
Intersections and negation describe overlap and exclusion. Such operations fit pattern-based reasoning, but no implementation should be described as perfectly handling every complex program merely because its foundation is mathematical.
The Evolution: From v1.17 to the Latest Milestones
The implementation has arrived in multiple releases. A staged rollout documents progress; it does not by itself guarantee stability for every application.
1.17, June 12, 2024: the first integration tracked primitive types and maps, including structs, and diagnosed certain local inconsistencies. It did not yet infer guards or propagate types between functions. Tuples, lists and functions were initially treated as indivisible types rather than fully tracking their contents.
1.18, December 19, 2024: expanded tuple/list and call analysis. 1.19, October 16, 2025: added anonymous-function inference and protocol checking. 1.20, June 3, 2026: completed the first inference milestone across language constructs without new user annotations. @type is not a new directive activating this checker.
The following examples target the documented 1.20 inference model. They deliberately contain bad calls for illustration; do not treat them as production-ready modules or as recorded compiler sessions.
Hands-On: How the Elixir Type Checker Works
Start with a synthetic numeric transformation, not user data or a tax calculation. The good and bad call sites differ only in the kind of argument supplied. No financial rate or payment behavior is being recommended.
defmodule ScaleDemo do
# Teaching example only; not compiled here.
def double(value) when is_number(value), do: value * 2
def good_example, do: double(10)
def bad_example, do: double("ten")
end
The guard when is_number(value) limits the accepted clause to numbers. The bad call passes a binary string. That mismatch is visible by inspection; the example does not need a legacy @spec declaration to express its guard.
A known binary and the numeric guard are disjoint. This is the kind of incompatible call the documented checker is designed to diagnose. The exact diagnostic depends on version and context; none was captured here.
Illustrative explanation, not compiler output:
The call double("ten") supplies a binary value.
The selected function clause accepts only numbers.
Inspect the actual diagnostic in your recorded toolchain version.
Existing code can benefit from inference without annotation churn. That is not a zero-configuration guarantee for an arbitrary project: supported language/runtime versions, dependency compatibility and the project’s warning policy still matter.
Typing Maps and Structs
Maps and structs can carry information about field shapes and values. Keep the distinction between recognizing a known incompatible value and proving that every possible runtime value is acceptable.
Use a synthetic workflow item with a stage tag. This retains the original lesson—struct pattern matching and a field update—without suggesting that a caller-controlled role field is an authorization system.
defmodule WorkflowItem do
defstruct [:title, :stage]
end
defmodule WorkflowDemo do
# Synthetic values only; not an authorization mechanism.
def mark_ready(%WorkflowItem{stage: :reviewed} = item) do
%{item | stage: :ready}
end
def good_example do
mark_ready(%WorkflowItem{title: "Example", stage: :reviewed})
end
def bad_example do
mark_ready(%WorkflowItem{title: "Example", stage: :draft})
end
end
The bad example supplies :draft, while the pattern requires :reviewed. These are distinct atom values. The valid example matches and constructs an updated struct; it does not mutate the original value. Actual compiler wording remains unverified here.
Such feedback can expose an incorrectly staged value before execution. It cannot establish that an external workflow actually happened, that a requester is authorized or that every production failure has been eliminated.
The Roadmap: What's Next?
Compilation cost must be measured on a representative project. The 1.19 release describes lazy module loading and optional parallel dependency compilation, including resource and compatibility caveats. Those changes are not evidence that type checking has zero cost or that mix compile never regresses. No benchmark was run here.
Separate released capabilities, documented direction and tooling availability:
- Protocols: 1.19 already introduced checking of dispatch and implementations. Do not collapse protocols and behaviours into a single promised future feature, or infer that every form of dynamic dispatch is fully verified.
- Signatures: user-supplied signatures for the new system remain a separate planned step. Existing
@specand@typebelong to the older typespec system; they do not automatically become the new checker’s compile-time assertions. Do not invent a release deadline. - Editors: a language server such as Expert can surface diagnostics through a compatible client. Editor support, server configuration and compilation timing determine what appears; an instant warning in every named editor is not guaranteed.
Why This Matters to You
Treat type diagnostics as one additional feedback channel. They do not make Elixir’s guarantees identical to Go’s or Rust’s, and they do not certify an application’s concurrency, deployment or hot-upgrade behavior.
For an evaluation, record Elixir and Erlang/OTP versions, review dependency compatibility, and examine diagnostics in an isolated copy of the project before considering deployment. Retain tests and input validation. This article performs no upgrade, package installation or production operation.
What Do You Think?
Which diagnostics are useful in your project, and which uncertainties still need tests or runtime validation? Compare concrete, versioned examples rather than framing dynamic programming as careless by definition.
If comments are available, discuss only small sanitized examples and the relevant toolchain version. Do not post credentials, private project code or personal data. The original newsletter invitation had no verified destination and is not repeated here.
Until next time, happy coding!
Primary references
- Version 1.17: initial local checks
- Version 1.18: expanded call and container analysis
- Version 1.19: protocols, anonymous functions and compilation
- Version 1.20: released inference milestone
- Current gradual set-theoretic type reference
- Pattern matching, guards and rebinding
- Legacy typespec reference at v1.20.0
- Formal type-system design research
- Expert language-server project
- Expert compilation events and LSP diagnostics